【问题标题】:Discord Node.js bot Log recieved messages to consoleDiscord Node.js bot 将收到的消息记录到控制台
【发布时间】:2020-09-21 03:50:07
【问题描述】:

我对 discord.js 和 node.js 并没有真正的经验,但我想知道如何将发送到机器人的 DM 记录到控制台。这是我用来向不同人发送消息的代码。

case 'senddm':
  mention = msg.mentions.users.first();
  msg.delete();
  if (mention == null) { return; }
  mentionMessage = msg.content.slice(9);
  mention.sendMessage(mentionMessage);
  console.log(`Send message: ${mentionMessage}`)
break;

【问题讨论】:

  • 你使用的是什么版本的 discord.js?
  • 如何检查?
  • 检查你的package.json文件
  • 我在 "Package.json" discord.js@11.5.1 中找到了这个
  • 您是否遇到任何错误?

标签: node.js bots discord discord.js


【解决方案1】:

您可以检查您提到的用户的 id 是否与您的机器人相同。

case 'senddm':
  mention = msg.mentions.users.first();
  msg.delete();
  if (mention == null) { return; }
  mentionMessage = msg.content.slice(9);
  mention.sendMessage(mentionMessage);

  if(mention.id === "your bot id here"){
      console.log(`Send message: ${mentionMessage}`)
  }
break;

【讨论】:

  • 我真的不知道你从哪里得到的,但我只想知道如何将我的机器人到达控制台的 DM 记录下来
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-11-03
  • 2018-05-30
  • 2021-11-15
  • 1970-01-01
  • 1970-01-01
  • 2020-07-15
  • 1970-01-01
相关资源
最近更新 更多