How can i check in discord.js if the used string is a channel on my discord?
discord app output: #channel,
console output: <#732610022386827404>
if(msgchannel == a_exisiting_channel){
return;
}
Why don't you just use message.mentions.channels.first()
Related
how do you check if the channel is full in discordJS v13?
ex. if the !join then if the channel is full return a message
You have to get the channel object first. Then use VoiceChannel.full() to check if a voice channel is full.
I am currently working on a music discord bot that I have been working on for a while now, but I couldn't seem to figure out how to get my bot to join the voice channel. So, I have completely erased everything, and I am starting from scratch. I have managed to code part of the bot, but I have run into an issue. That issue is that I don't quite seem to know how to make the music bot check to see if the author of the command is in a voice channel.
My code for my music bot.:
You are already checking if the member is in a voice channel line 18.
And to join a voice channel you can use the VoiceChannel.join() method
if (msg.content.toLowerCase() === "+join") {
if (msg.member.voice.channel) {
msg.member.voice.channel.join();
msg.channel.send("Successfully joined the voice channel");
} else return message.channel.send("Please join a voice channel first");
}
I am using discord.js to implement a bot in the discord. When I use a command in any channel in my server, my bot responds to it, but I would like that my bot only worked if someone was sending the commands inside a private chat with the bot, how do I do that?
If you only want it to work between DMs, do
if (!message.channel.type == `dm`) return;
//other commands
You can check if the message was sent in a certain channel by checking the Message.channel.id property.
client.on("message", message => {
if (message.channel.id !== "ChannelID") return false;
// Execute your commands here
});
I have such a problem that I want to send a message via the bot only to a given channel. How can I do this?
Client.channels.cache.get(id).send(text)
This don't work
You can do like so with discord.js v12:
let channel = client.guilds.cache.get('ID_of_the_guild_in_which_the_channel_is_in').channels.cache.get('channel_ID');
if(channel) channel.send('your message');
I will refer to this picture:
I am making a Discord bot in JavaScript and I am stuck somewhere
I have a say command which you use like !say Text here and the bot will send a plain message saying Text here
Now I want the bot to send an embed message used the same and I want the bot to have a title, image, link and a author set on default. When someone does !sayEmbed #everyone loco (the text there)
There you go:
client.on("message", function(msg){
if (msg.content.split("!")[0] != "sayEmbed") return;
if (msg.content.split(" ")[1]){
// if args exist
msg.channel.send(new MessageEmbed()
.setTitle("Genius Mind")
.setDescription(msg.content.split("!sayEmbed")[0])
.setColor("#148837")
.setAuthor(`#everyone react now | {msg.createdAt.toDateString}`)
.setURL("someURL.example.com")
.setThumbnail("foo.bar/link/to/image")
)
}
}
I couldn't find any url and image url, so change that yourself.