英文:
(discord.js) Bot doesnt reply in discord
问题
我有一个问题:<br>
我在命令提示符中运行脚本非常顺利,但当我在 Discord 服务器中输入 "hello" 时,没有回复。你有任何想法吗?
权限设置对于机器人是正确的,并且它也在线。有什么建议吗?
console.log("Beep Beep");
const { Client, GatewayIntentBits } = require("discord.js");
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
client.login("TOKEN");
client.on("ready", readyDiscord);
function readyDiscord() {
console.log("ok");
}
client.on("message", gotMessage);
function gotMessage(msg) {
console.log(msg.content);
if (msg.content === "Hello") {
msg.reply("Hi");
}
}
总结:
- 在 cmd.exe 中运行 node bot.js
- 等待确认(控制台回复:ok)
- 打开 Discord 并进入 "general" 频道。
- 输入 "Hello"
- 机器人没有回应。
英文:
I have an issue with this:<br>
I run the script quite smoothly in the command prompt, but when I type "hello" in the discord server, no replies are coming back. Do you have any idea?
The permission rights are in order for the bot and are as well online. Any suggestion?
console.log("Beep Beep");
const { Client, GatewayIntentBits } = require("discord.js");
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
client.login("TOKEN");
client.on("ready", readyDiscord);
function readyDiscord() {
console.log("ok");
}
client.on("message", gotMessage);
function gotMessage(msg) {
console.log(msg.content);
if (msg.content === "Hello") {
msg.reply("Hi");
}
}
Summarizing:
- run node bot.js in cmd.exe
- waiting confirmation (console reply: ok)
- Open discord and go to "general" channel.
- Digit "Hello"
- No reply from the bot.
答案1
得分: 0
In Discord.js v14, the message
event was changed to messageCreate
. If your permissions are set up correctly and you have privileged intents enabled for message content, then this is probably the root of your issue. Just change it accordingly in your .on()
event handler registration:
console.log("Beep Beep");
const { Client, GatewayIntentBits } = require("discord.js");
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
client.login("TOKEN");
client.on("ready", readyDiscord);
function readyDiscord() {
console.log("ok");
}
client.on("messageCreate", gotMessage);
function gotMessage(msg) {
console.log(msg.content);
if (msg.content === "Hello") {
msg.reply("Hi");
}
}
英文:
In Discord.js v14, the message
event was changed to messageCreate
. If your permissions are set up correctly and you have privileged intents enabled for message content, then this is probably the root of your issue. Just change it accordingly in your .on()
event handler registration:
console.log("Beep Beep");
const { Client, GatewayIntentBits } = require("discord.js");
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
client.login("TOKEN");
client.on("ready", readyDiscord);
function readyDiscord() {
console.log("ok");
}
client.on("messageCreate", gotMessage);
function gotMessage(msg) {
console.log(msg.content);
if (msg.content === "Hello") {
msg.reply("Hi");
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论