I Want To Set Default System Channel On Discordjs v12 - discord.js

I Want To Set System Channel Messages With Discordjs v12
i tried:
message.guild.systemChannel.set(channel)
But It Doesent Work

First you should look for the specific channel like:
const testChannel = client.channels.cache.find(channel => channel.name === "yourchannelname");
and then:
message.guild.systemChannel.set(testChannel)
I would do it when client.once is ready or guildMemberAdd
Let me remind you that this is working for me in discord.js 12.5.1 and last version is 13.5.0

Related

How to register slash commands automaically when bot enters server discord.js

As of now i have my bot manually deploy slash commands to the server. What should i do so that the bot self registers the slash commands without using a prefix command/registers itself as soon as it enters a server. Here's the code i'm using as of now for deploying slash commands. I'm using discord.js V13 btw
if(content === "!deploy guild") {
if(!message.guild) return;
console.log("Deploying commands in guild...");
await message.guild.commands.set(commands).then(() => console.log(`Commands deployed in guild ${message.guild.name}!`));
await message.reply("Deployed in guild!");
You would be looking at the Events#GuildCreate emitter, once there is a new guild the bot is added to, this event is fired ( emitted ) and you can add your commands / do any specific task you wish to do on joining a new guild
Setting up a listener for it with your client your code would look something like so:
/*
* client is your discord.js Client
* commands obj is your command data you want to add to the guild
*/
client.on('guildCreate', async (guild) => {
guild.commands.set(commands).then(() =>
console.log(`Commands deployed in guild ${guild.name}!`));
})

Discord: Reading messages from one channel in a (non-admin perm) server, and posting it to another (with admin perms)

I am new to Discord API framework.
ServerFROM is a public server that I was invited to (non-admin perms). Hence I cannot add bots there. But I can view the content in ChannelFROM (a text channel in ServerFROM)
I have my own ServerTO (in which I have admin perms and so can do anything). Inside of which, I have the target ChannelTO
I want to deploy a listener on ChannelFROM, such when there is a new message (announcement) in ChannelFROM, I want it to be read and reposted in ChannelTO.
Something similar to what is done in this Stackoverflow issue, except that I cannot have some script run locally 24x7 on my machine. Maybe use Github Actions or something similar?
How can I go about doing it? Any ideas are appreciated. Maybe some form of a server, or just a custom Discord bot
And thanks in advance.
you can use Custom bot for that. I dont know other way
here's how i do it
1st : We Get the ID of the Channel that you wanted to listen
2nd : We make a Output or where the bot copy the message from and send it
3rd : Bot required a permission to view the channel and send message
or in the nutshell ( sorry if im bad at explaining )
client.on("messageCreate", message => {
if(message.author.bot) return;
if(message.channel.id === ID_HERE) // ChannelFROM in ID_HERE
{
let MSG = message.content
let Author = message.member.displayName
let Avatar = message.author.displayAvatarURL({dynamic: true})
const Embed = new MessageEmbed()
.setAuthor(Author , Avatar )
.setDescription(MSG)
.setColor("RANDOM")
client.channels.cache.get(ID_HERE).send({ embeds: [Embed] }) // SendTo in ID_HERE
}
})
you can remove if(message.author.bot) return; if you want it also read other bot message on that specific channel

How do you find a channel using its name in Discord.js?

I tried using this to find a channel named "information" and to send a message in it:
let channel = message.guild.channels.cache.find(channel => channel.name.toLowerCase() === 'information')
channel.send('test')
And using that code resulted in this error:
let channel = message.guild.channels.cache.find(channel => channel.name.toLowerCase() === 'information')
^
TypeError: message.guild.channels.cache.find is not a function
I tried npm install discord.js to update the package, but it still didn't work. I also tried client.channels.cache.find, But it ended up receiving the same error. Am I doing something wrong here?
According to the docs you're doing it right ...
but according to reddit, there is no need to call cache and you can just call :
let channel = message.guild.channels.find(
channel => channel.name.toLowerCase() === "information"
)
this corresponds to what i am doing with my bot, and this worked a few months ago
guild.channels.array().filter(c => c.name === 'General')
Seems like guild.channels is already a collection, don't know if it's a mistake in the Documentation or if it's a really recent version that changed that ...
[edit] found the problem
in the documentation, there are two versions (up in the toolbar) v12 (default) and v11
it seems like they added the .cache in the v12, but maybe this one is not on npm already.
they have an alert about breaking changes that links to this page
where they explain how to switch to v12 https://discordjs.guide/additional-info/changes-in-v12.html
You have to write it like this:
let channel = message.channel.guild.channels.cache.find((channel) => channel.name.toLowerCase() === `information`
I think it didn't work because you need brackets around the variable channel.

Discord.js getting guildmember from username

I hope you can help I can't seem to find a solution for this speific use case.
When a user joins my server I want to show a welcome embed and update their nickname in the server.
I have the embed bit working fine but I cant seem to get the guildMember using the user supplied.
code: Discord.js v12.2
bot.on('guildMemberAdd', member=> {
const channel = member.guild.channels.cache.find(channel => channel.name === 'cloudservertesting');
if(!channel) return;
const embed = new Discord.MessageEmbed()
.setColor('#992D22')
.setTitle('New Member')
.setDescription(`**${member.user.username}** has joined Red Wine Gaming!, Welcome!`)
.setThumbnail(`${member.user.displayAvatarURL()}`)
.setTimestamp();
channel.send(embed);
//Change users Nickname Here
});
member.guild.members returns an object but it wont let me .filter
It would be ideal if I could get the guildmember from the mumer.user supplied on the user add so i can setNickname.
The GuildMember instance you're looking for is your parameter member. Check the documentation on the Client#guildMemberAdd event and you'll see the parameter is a GuildMember.
member.setNickname('foo')
.catch(console.error);
member.guild.members returns an object but it wont let me .filter
That would be because as of v12, it's a Manager, so you would have to utilize the cache property to use Collection#filter(). See GuildMemberManager specifically.

Discord.js moving person to random VoiceChannel

I'm making a discord bot that will has a feature to move user's to a random voice channel if they want. I searched the internet 3 hours straight and checked the whole documentation. But still can't find anything.
note : I know this bot idea looks useless. But that's what I need.
code :
let voiceChannels = message.guild.filter(g => **idk how to check if it's vc** );
that's what I just found in 3 hours.
You'd need to access the guild's channels and then choose a random channel of type voice.
So in your case, it'd be:
let voiceChannel = message.guild.channels.cache.filter((channel) => channel.type === "voice").random();
if (!message.member.voice.channel) return message.reply("User is not in a voice channel");
await message.member.voice.setChannel(voiceChannel);

Resources