I know some basic python and I decided to try my hand at making a discord bot, but failed to get the bot to respond to a command. I tried changing the '-ping' to 'ping' and tried typing on my discord server:
ping -ping
but neither did anything. Furthermore,
console.log('This does not run');
does not show up in console.
I'm not quite sure where I wrong. Any help would be appreciated. Thanks!
const {Client, Intents} = require('discord.js');
const {token} = require('./config.json');
const client = new Client({intents:[Intents.FLAGS.GUILDS]});
const prefix = '-';
client.once('ready', () => {
console.log('Bot works');
});
client.on('message', message => {
console.log('This does not run');
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ */);
const command = args.shift().toLowerCase();
if(command === '-ping'){
message.channel.send('pong');
}
});
client.login(token);
I think you need the GUILD_MESSAGES
intent enabled. You can add it to the list of intents in the client constructor, like so:
const client = new Client({intents:[Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]});
thank you very much i had the same issue but resolved it thanks to your suggestion
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.