when using commands in succession, an error appears that the connection has already been destroyed. I'm looking for a solution.
error message is
Cannot destroy VoiceConnection - it has already been destroyed
my code is
voiceConnection = joinVoiceChannel({
channelId: message.member.voice.channelId,
guildId: message.guildId,
adapterCreator: message.guild.voiceAdapterCreator,
});
const stream = discordTTS.getVoiceStream(txtr);
const audioResource=createAudioResource(stream, {inputType: StreamType.Arbitrary, inlineVolume:true});
voiceConnection = await entersState(voiceConnection, VoiceConnectionStatus.Connecting, 5_000);
audioPlayer.play(audioResource, {seek: 0, volume: 1.0})
voiceConnection.subscribe(audioPlayer);
audioPlayer.play(audioResource)
audioPlayer.on(AudioPlayerStatus.Idle, () => {
voiceConnection.destroy();
});```
Related
const Discord = require('discord.js');
module.exports = {
name: 'unban',
aliases: ['uban', 'unban'],
category: 'misc',
permissions: ['BAN_MEMBERS'],
description:
'Use this command to permanately or temporary ban a server member from Sekai.',
/**
* #param {Discord.Message} message
* #param {Array} args
*/
async execute(message, args) {
if (message.mentions.users.size === 0)
return message.reply('Please mention a user to unban ❌');
const targetid = message.mentions.users.first().id;
if (targetid === message.client.user.id)
return message.reply(
"Me? Really? That's not very nice, I guess you failed 🤡"
);
const targed = await message.guild.members.cache.get(targetid);
let reason = [];
if (args.length >= 2) {
args.shift();
reason = args.join(' ');
} else reason = 'No Reason provided';
try {
let extra = '';
try {
const embed = new Discord.MessageEmbed()
.setTitle('Moderation message regarding on your **BAN**')
.setAuthor("Joony's Den")
.setDescription(
`you have been banned from **${message.guild.name} ✅ **\nReason for ban: **${reason}\n${extra}**`
)
.addField('Contact','If you believe that your ban was unjustified, please feel free to contact any of these staff members. **JOONY#9513** or any of administrators online.')
.setColor('#2243e6')
.addField('Appeal Accepted?','if your appeal was accepted, please join using this link. your link will expire after 1 use. **https://discord.gg/4yuCzUC7aw**')
.addField(
'Appeal',
'Because you have been banned from the server, you will have one chance to appeal 🔨. Your appeal will be processed to the administrators or appeal managers ✅ **[CLICK HERE TO APPEAL](https://forms.gle/atc75ZftpdfJhfH56)**'
);
targed.send(embed);
} catch (error) {
extra = 'Messaging the user has failed! ❌';
}
setTimeout(() => {
targed.unban(targed, [reason])
const embed = new Discord.MessageEmbed()
.setTitle('User unbanned')
.setDescription(
`${
targed.tag || targed.user.username
} has been sucessfully unbanned from **${
message.guild.name
} ✅ **\nReason for unban: **${reason}\n${extra}**`
)
.setColor('#FA2657');
message.channel.send(embed);
}, 2000);
} catch (error) {
message.channel.send(
`I could not unban the given member, make sure that my role is above member! ❌`
);
}
},
};
Hello! how do I unban the user using this format, it has an error saying "guild.unban is undefined"
it has an error saying
targed.unban([reason])
^
TypeError: targed.unban is not a function
at Timeout._onTimeout (C:\Users\Joon\Documents\GitHub\Discord-Bot\commands\misc\unban.js:49:16)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
You cannot unban a GuildMember (a banned user is not a member of a Guild). You should call unban on GuildMemberManager. See https://discord.js.org/#/docs/main/stable/class/GuildMemberManager?scrollTo=unban
I have been working on a bulk delete message logs, but for whatever reason it can not get the ID of the channel from the guild in a seperate file. so it returns that ID is undefined.
THE CODE
module.exports = async (bot, messages) => {
const length = messages.array().length
let channels = JSON.parse(
fs.readFileSync('././database/messageChannel.json', 'utf8')
);
let channelId = channels[messages.guild.id].channel;
let msgChannel = bot.channels.cache.get(channelId);
if (!msgChannel) {
return console.log(`No message channel found with ID ${channelId}`);
}
let mEmbed = new MessageEmbed()
.setAuthor(messages.guild.name, messages.guild.iconURL({dynamic: true}))
.setColor(red_light)
.setDescription(`**Bulk Delete in <#${messages.channel.id}>, ${length} messages deleted.**`)
.setTimestamp()
msgChannel.send(mEmbed)
}
In the index file I specified the
messageDeleteBulk
When trying to send the message to the messageChannel it does not send because 'id' is undefined. Is there something I am missing?
So, the command works fine all I forgot was that earlier when I defined length I used
messages.first()so where I just put messages I have to add .first()
THE NEW CODE
module.exports = async (bot, messages) => {
let channels = JSON.parse(
fs.readFileSync('././database/messageChannel.json', 'utf8')
);
let channelId = channels[messages.first().guild.id].channel;
let msgChannel = bot.channels.cache.get(channelId);
if (!msgChannel) {
return console.log(`No message channel found with ID ${channelId}`);
}
const length = messages.array().length;
let mEmbed = new MessageEmbed()
.setAuthor(messages.first().guild.name, messages.first().guild.iconURL({dynamic: true}))
.setColor(red_light)
.setDescription(`**Bulk Delete in <#${messages.first().channel.id}>, ${length} messages deleted.**`)
.setTimestamp()
msgChannel.send(mEmbed)
}
Now it logs the bulk deleted messages and does not return any errors.
i am tring to do that every time someone that joins my server blocks dms the bot will open a channel and send a verify link instead of a dm
what I stuck on (store the channel and stuff like that)
client.on('guildMemberAdd', member => {
const linkId = pool.createLink(member.id);
const embed = new Discord.MessageEmbed()
.setTitle('reCAPTCHA Verification')
.setDescription(`To gain access to this server you must solve a captcha. The link will expire in 15 minutes.\nhttp://${domain == '' ? 'localhost:8050' : domain}/verify/${linkId}`)
.setColor('YELLOW');
channel = client.channels.cache.get(`${logschannel}`);
channel.send('user has joined if you dont get another message in a few minutes please check if the user has verifyed ');
member.send(embed).catch(() => {message.guild.channels .create(member.id, { type: "text" }), channel.send('#here'); const errore = new Discord.MessageEmbed()
.setTitle('reCAPTCHA Verification')
.setDescription(`The user with the id ${member.id} is blocking dms please check on that!`)
.setColor('RED')
channel.send(errore)})
what I had
client.on('guildMemberAdd', member => {
const linkId = pool.createLink(member.id);
const embed = new Discord.MessageEmbed()
.setTitle('reCAPTCHA Verification')
.setDescription(`To gain access to this server you must solve a captcha. The link will expire in 15 minutes.\nhttp://${domain == '' ? 'localhost:8050' : domain}/verify/${linkId}`)
.setColor('YELLOW');
channel = client.channels.cache.get(`${logschannel}`);
channel.send('user has joined if you dont get another message in a few minutes please check if the user has verifyed ');
member.send(embed).catch(() => {channel.send('#here'); const errore = new Discord.MessageEmbed()
.setTitle('reCAPTCHA Verification')
.setDescription(`The user with the id ${member.id} is blocking dms please check on that!`)
.setColor('RED')
channel.send(errore)})
To create the channel you can just use GuildChannelManager#create (aka guild.channels.create).
member.guild.channels.create(`${member.author.username}-verification`, {
permissionOverwrites: [
{
id: member.author.id,
allow: ['VIEW_CHANNEL'],
},
{
id: member.guild.id,
deny: ['VIEW_CHANNEL'],
},
]
});
To send a message to the channel there are two ways you can do it.
A: Store the channel object.
const verifyChannel = member.guild.channels.create(`channel`);
verifyChannel.send('Message!')
B: Use .then() as creating as channel returns a promise.
member.guild.channels.create(`channel`)
.then(chan => {
chan.send('Message!');
});
im not experienced in javascript, i followed some tutorials to have different commands in separated files and they work fine, but i cannot fix an error in a msg command:
module.exports = {
name: 'msg',
description: 'sends a message to any channel the bot can access',
execute(message, args){
var msg = args.slice(1);
msg = msg.join(" ");
//let channel = Vot.channels.cache.get(args[1])
let server = args[0]
if(!server) return message.channel.send(msg);
if(!msg) return message.reply("where is the message");
Vot.channels.cache.get(server).send(msg);
}
}
its supposed to be .#msg (channel_id) <message>, sending the message to the desired channel
(it worked before in a switch statement in the main file) i have tried solutions from other questions like const { client } = require('../Server.js') at the top but it didnt work, are there any other options?
You should use message.client instead of Vot:
module.exports = {
name: 'msg',
description: 'sends a message to any channel the bot can access',
execute(message, args){
var msg = args.slice(1);
msg = msg.join(" ");
//let channel = message.client.channels.cache.get(args[1])
let server = args[0]
if(!server) return message.channel.send(msg);
if(!msg) return message.reply("where is the message");
message.client.channels.cache.get(server).send(msg);
}
}
I need a AutoRole command discord.js when somebody join my discord server he gets the Discord Member role.
Ive tryied some code but it doesnt work.
const discord = require("discord.js");
const config = require('../config.json');
module.exports.run = async (bot, message, args) => {
let target = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
let reason = args.slice(1).join(' ');
let logs = message.guild.channels.find('name', config.logsChannel);
if (!message.member.hasPermission('BAN_MEMBERS')) return message.reply('you do not have permissions to use this command!s');
if (!target) return message.reply('please specify a member to ban!');
if (!reason) return message.reply('please specify a reason for this ban!');
if (!logs) return message.reply(`please create a channel called ${config.logsChannel} to log the bans!`);
let embed = new discord.RichEmbed()
.setColor('RANDOM')
.setThumbnail(target.user.avatarURL)
.addField('Banned Member', `${target.user.username} with an ID: ${target.user.id}`)
.addField('Banned By', `${message.author.username} with an ID: ${message.author.id}`)
.addField('Banned Time', message.createdAt)
.addField('Banned At', message.channel)
.addField('Banned Reason', reason)
.setFooter('Banned user information', target.user.displayAvatarURL);
message.channel.send(`${target.user.username} was banned by ${message.author} for ${reason}`);
target.ban(reason);
logs.send(embed);
};
module.exports.help = {
name: 'ban'
};
When they join they get the Discord Member role.
You can use the guildMemberAdd event to do actions on new users.
client.on("guildMemberAdd", (member) => {
member.addRole('ROLE ID HERE')
});