我是编程专业的大三学生.我知道 node.js 并且想为不和谐写我自己的机器人.
I am a junior in programming. I know node.js and want to write my own bot for discord.
下面写的我的代码不起作用.你能帮我解决这个问题吗?
My code which is written below doesn't work. Can you help me with this?
const { Client, Intents } = require('discord.js');
const config = require('./config.json');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', message=>{
if(!message.content.startsWith(config.prefix) || message.author.bot) return;
const args = message.content.slice(config.prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(command === 'ping'){
message.channel.send('pong!');
}
})
client.login(config.token);
GUILDS Intent 不足以接收消息.您还需要 GUILD_MESSAGES 消息意图:
GUILDS intent is not enough to receive messages. You will also need GUILD_MESSAGES intent for messages:
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES
]
})
这篇关于我的不和谐机器人代码正在运行,但没有响应我的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
使用 discord.js 检测图像并响应Using discord.js to detect image and respond(使用 discord.js 检测图像并响应)
检查 Discord 服务器中是否存在用户 IDCheck if user ID exists in Discord server(检查 Discord 服务器中是否存在用户 ID)
公会成员添加不起作用(discordjs)Guild Member Add does not work (discordjs)(公会成员添加不起作用(discordjs))
使用 REPLIT 创建我的第一个机器人,但总是错误Creating my first bot using REPLIT but always error Discord.JS(使用 REPLIT 创建我的第一个机器人,但总是错误 Discord.JS)
如何为我的 Discord.js 机器人编写事件/命令处理程How do I code event/command handlers for my Discord.js bot?(如何为我的 Discord.js 机器人编写事件/命令处理程序?)
如何从 Discord.js 中的用户名中查找用户 ID?How to find a User ID from a Username in Discord.js?(如何从 Discord.js 中的用户名中查找用户 ID?)