A member is going to disconnect a bot in a voice channel, but he can disconnect the call without being inside the voice channel. How can I fix this?
const voiceChannel = message.member.voice.channel;
const { channel } = message.member.voice || message.member.voice.channel;
const guildQueue = client.queue.get(message.guild.id);
const member = member.voice.channel;
// Check if the user is in the same channel. If not then it will not be able to disconnect the bot.
if (message.guild.me.voice.channel || guildQueue){
const embed = new MessageEmbed()
.setColor('#5865F2')
.setDescription(`You're not on the call.`)
return message.channel.send({ embeds: [embed] });
}
// Disconnects the bot from the call.
const embed = new MessageEmbed()
.setColor('#5865F2')
.setDescription(`I'm no longer connected.`)
guildQueue.connection.destroy();
client.queue.delete(message.guild.id);
return message.channel.send({ embeds: [embed] });
}
Related
I've tried multiple ways to try to get it to send but it shows no error and doesn't send into channel.
const { MessageEmbed } = require('discord.js');
client.on("ready", async () => {
const embed = new MessageEmbed()
.setTitle(`Bot Status!`)
.setDescription(`${client.user.username} **Is Online!**`)
const channel = client.channels.cache.get('1006667208371490946')
channel.send({embeds: [embed]})
})
in the latest Discord.js version (V14) the correct way is
const { EmbedBuilder } = require('discord.js');
client.on("ready", async () => {
const embed = new EmbedBuilder()
.setTitle(`Bot Status!`)
.setDescription(`${client.user.username} **Is Online!**`);
const channel = client.channels.cache.get('1006667208371490946')
channel.send({embeds: [embed]})
});
If this is not solving your issue,
try to add a console.log(channel) just before channel.send({embeds: [embed]})
If the result is undefined, the problem is the bot can't get in your cache the channel you want. In that case you can fetch (Link to a post speaking about this)
In the other case the bot can't send a message in the channel, could be a permission issue but you can add a .then() / .catch() to see if error is showed or not.
Hope this can helps you
I think the problem is that you don't have the client to call.
const { MessageEmbed } = require('discord.js');
client.on("ready", async (/*client not found in here*/) => {
const embed = new MessageEmbed()
.setTitle(`Bot Status!`)
.setDescription(`${client.user.username} **Is Online!**`)
const channel = client.channels.cache.get('1006667208371490946')
channel.send({embeds: [embed]})
})
So try to add client
const { MessageEmbed } = require('discord.js');
client.on("ready", async(client) => {
const embed = new MessageEmbed()
.setTitle(`Bot Status!`)
.setDescription(`${client.user.username} **Is Online!**`)
const channel = client.channels.cache.get('1006667208371490946')
channel.send({embeds: [embed]})
})
on my say command it's not embedded so it lets members #everyone I want to embed the bot's reply to prevent that.
i tried other embeds but they did not work out due to them being
outdated i tried my own but it did not work
command I use:
client.on('message',
function(msg){
if(msg.content === "v!say"){
I don't lnow what to put after
There are several things you could do on this
FYI message is deprecrated and you should use the event listener below:
client.on(`messageCreate`, async (msg) => {
// code here
};
Prevent #everyone and #here
if(msg.content === `v!say` && !msg.content.includes(`#everyone`) && !msg.content.includes(`#here`){
let message2send = //however you already do this
await msg.channel.send({
content: message2send,
});
}
Embed Message
const { MessageEmbed } = require(`discord.js`);
//put at top of file
if(msg.content === `v!say`){
let message2send = //however you already do this
let embed = new MessageEmbed()
.setDescription(message2send)
await msg.channel.send({
embeds: [embed],
});
}
Do Both
const { MessageEmbed } = require(`discord.js`);
//put at top of file
if(msg.content === `v!say` && !msg.content.includes(`#everyone`) && !msg.content.includes(`#here`){
let message2send = //however you already do this
let embed = new MessageEmbed()
.setDescription(message2send)
await msg.channel.send({
embeds: [embed],
});
}
UPDATE: this answer is not for Discord.js v14+ as MessageEmbed is now EmbedBuilder
If the user does not have the role, it will add the role, but if the user already has the role, it will remove the role. How can I do that?
if (message.member.roles.has(role.id)){
const embed = new MessageEmbed()
.setColor('#5865F2')
.setDescription(`Role added ${role} to ${member}.`)
.setFooter(`Requested by ${message.author.username}`)
member.roles.remove(role.id)
message.channel.send({ embeds: [embed] });
} else {
const embed = new MessageEmbed()
.setColor('#5865F2')
.setDescription(`Role removed ${role} to ${member}.`)
.setFooter(`Requested by ${message.author.username}`)
member.roles.add(role.id)
message.channel.send({ embeds: [embed] });
}
The reason you are getting this error is because the .has() function does not exist in the roles property. Instead, you need to fetch them using .fetch() or use the cached roles by using roles.cache.has(). So your code might look something like this:
if (message.member.roles.cache.has(role.id)){
const embed = new MessageEmbed()
.setColor('#5865F2')
.setDescription(`Role added ${role} to ${member}.`)
.setFooter(`Requested by ${message.author.username}`)
member.roles.remove(role.id)
message.channel.send({ embeds: [embed] });
} else {
const embed = new MessageEmbed()
.setColor('#5865F2')
.setDescription(`Role removed ${role} to ${member}.`)
.setFooter(`Requested by ${message.author.username}`)
member.roles.add(role.id)
message.channel.send({ embeds: [embed] });
}
I currently am having trouble running this code it used to stop the bot/replit when a person joins the bot/replit now it declares it as an empty message
let Discord = require("discord.js");
let client = new Discord.Client();
client.on("ready", () => {
client.user.setPresence({ 'activity': { name: "Test}})
})
client.on('guildMemberAdd', member => {
const embed = new Discord.MessageEmbed()
.setTitle(`Welcome ${member.user.tag}!`)
.setDescription(`You are member ${member.guild.memberCount}`)
const channel = member.guild.channels.cache.find(ch => ch.name === 'welcome-channel')
channel.send({
embeds: [embed]
})
})
client.login("")
You can use client.on('guildMemberAdd') and this for the embed =>
client.on('guildMemberAdd', member => {
const embed = new MessageEmbed()
.setTitle(`Welcome ${member.user.tag}!`)
.setDescription(`You are member ${member.guild.memberCount}!`)
const channel = member.guild.channels.cache.find(ch => ch.name === 'welcome-channel')
channel.send({
embeds: [embed]
})
})
Ok so... I've been attempting to make a reaction roles command but it won't work. The role isn't given to the user. It gives me this error "ReferenceError: reaction is not defined"
Code:
const client = new Discord.Client({ partials: ["MESSAGE", "CHANNEL","REACTION"]});
client.on('message', async message => {
if(message.content === '>reactions'){
const embed = new Discord.MessageEmbed()
.setTitle('Reaction Roles')
.setDescription('React to obtain your roles!')
.setColor('#242323')
let MessageEmbed = await message.channel.send(embed)
MessageEmbed.react('👨👦')
}
if(reaction.message.partial) await reaction.message.fetch();
if(reaction.partial) await reaction.fetch();
if(user.client) return;
if(!reaction.message.guild) return;
if(reaction.message.channel.id === "759064796611215442") {
if(reaction.emoji.name === '👨👦'){
await reaction.message.guild.member.cache.get(user.id).roles.add('760838222057046046')
}
}
});