admin管理员组文章数量:1418022
For some reason the bot is posting in the discord more than once. I am unsure how to fix this at this moment. I've exhausted all options and even restarted the code and the bot itself and I am not to sure where to go on from here.
You can find my code below:
const Discord = require('discord.js');
const fs = require('fs');
const client = new Discord.client();
const prefix = '-';
clientmands = new Discord.Collection();
const mandFiles = fs.readdirSync('./mands/').filter(file => file.endsWith('.js'));
for (const file of mandFiles){
const mand = require(`./mands/${file}`);
clientmands.set(mand.name, mand);
}
client.once('ready', () => {
console.log('United is online');
});
client.on('message', message =>{
if(!message.content.startsWith(prefix) || message.author.bot ) return;
const args = message.content.slice(prefix.length).split(/ +/);
const mand = args.shift().toLowerCase();
if(mand === 'youtube'){
clientmands.get('youtube').execute(message, args);
} else if (mand == 'twitter'){
message.channel.send('');
}
});
youtube.js
module.exports = {
name: 'youtube',
description: "displays youtube channel!",
execute(message, args){
message.channel.send('');
}
}
For some reason the bot is posting in the discord more than once. I am unsure how to fix this at this moment. I've exhausted all options and even restarted the code and the bot itself and I am not to sure where to go on from here.
You can find my code below:
const Discord = require('discord.js');
const fs = require('fs');
const client = new Discord.client();
const prefix = '-';
client.mands = new Discord.Collection();
const mandFiles = fs.readdirSync('./mands/').filter(file => file.endsWith('.js'));
for (const file of mandFiles){
const mand = require(`./mands/${file}`);
client.mands.set(mand.name, mand);
}
client.once('ready', () => {
console.log('United is online');
});
client.on('message', message =>{
if(!message.content.startsWith(prefix) || message.author.bot ) return;
const args = message.content.slice(prefix.length).split(/ +/);
const mand = args.shift().toLowerCase();
if(mand === 'youtube'){
client.mands.get('youtube').execute(message, args);
} else if (mand == 'twitter'){
message.channel.send('https://twitter./UnitedPeoplesTV');
}
});
youtube.js
module.exports = {
name: 'youtube',
description: "displays youtube channel!",
execute(message, args){
message.channel.send('https://youtube./unitedpeoplestv?sub_confirmation=1');
}
}
Share
Improve this question
edited Jan 14, 2021 at 23:16
Zsolt Meszaros
23.2k19 gold badges58 silver badges69 bronze badges
asked Jan 14, 2021 at 22:31
JoeGoshJoeGosh
251 silver badge3 bronze badges
3
- 1 Have you got multiple instances of the bot running? – Pentium1080Ti Commented Jan 14, 2021 at 22:35
- No, there is only one bot in the discord unless I am missing something. – JoeGosh Commented Jan 14, 2021 at 22:51
- 2 Try resetting your IDE and Terminal – Elitezen Commented Jan 14, 2021 at 23:19
5 Answers
Reset to default 2I would suggest that you kick the bot from the server, restart your puter (or stop your hosting service - making sure for example if you're using pm2 that it isnt running multiple instances), and try again. Invite the bot back again from the discord applications webpage once you have pleted that.
Make sure there aren't two processes running, Look in task manager and see if there are two Node.js processes running, and if there are then it might be double running. Try ending them and then starting the bot again.
To make sure that there aren't multiple instances, you can reset your token in the discord developer portal inside your application and replace the old token with the new one. After that, you need to restart your bot with the new token.
This will stop all other processes because discord is stopping all connections due to the token reset.
Try adding this line of code:
if (message.author.bot) return;
It check is the author of the message is a bot and returns nothing if it's True.
Found an issue - there was a duplication because of process.env file - where I also stored the bot token, and because of that function worked twice (I exported function to another file and used it there).
本文标签: javascriptMy Discord bot is sending multiple messages at once using discordjsStack Overflow
版权声明:本文标题:javascript - My Discord bot is sending multiple messages at once using discord.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745283494a2651564.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论