Bot doesn’t reply in discord.

huangapple go评论132阅读模式
英文:

(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");
  }
}

总结:

  1. 在 cmd.exe 中运行 node bot.js
  2. 等待确认(控制台回复:ok)
  3. 打开 Discord 并进入 "general" 频道。
  4. 输入 "Hello"
  5. 机器人没有回应。
英文:

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(&quot;Beep Beep&quot;);

const { Client, GatewayIntentBits } = require(&quot;discord.js&quot;);

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent,
    GatewayIntentBits.GuildMembers,
  ],
});

client.login(&quot;TOKEN&quot;);

client.on(&quot;ready&quot;, readyDiscord);

function readyDiscord() {
  console.log(&quot;ok&quot;);
}

client.on(&quot;message&quot;, gotMessage);

function gotMessage(msg) {
  console.log(msg.content);
  if (msg.content === &quot;Hello&quot;) {
    msg.reply(&quot;Hi&quot;);
  }
}

Summarizing:

  1. run node bot.js in cmd.exe
  2. waiting confirmation (console reply: ok)
  3. Open discord and go to "general" channel.
  4. Digit "Hello"
  5. 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(&quot;Beep Beep&quot;);

const { Client, GatewayIntentBits } = require(&quot;discord.js&quot;);

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent,
    GatewayIntentBits.GuildMembers,
  ],
});

client.login(&quot;TOKEN&quot;);

client.on(&quot;ready&quot;, readyDiscord);

function readyDiscord() {
  console.log(&quot;ok&quot;);
}

client.on(&quot;messageCreate&quot;, gotMessage);

function gotMessage(msg) {
  console.log(msg.content);
  if (msg.content === &quot;Hello&quot;) {
    msg.reply(&quot;Hi&quot;);
  }
}

huangapple
  • 本文由 发表于 2023年3月12日 09:37:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/75710624.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定