【问题标题】:Is there a way to make the discord bot reply to someone's dm that it is prohibited to send private messages?有没有办法让不和谐机器人回复某人的 dm 禁止发送私人消息?
【发布时间】:2020-05-29 08:12:40
【问题描述】:

我希望我的 discord 机器人在有人 DM 时发送类似“您不允许在此处发送消息”之类的内容

这是我目前所拥有的:

if(message.channel instanceof Discord.DMChannel){
   return;
}

任何帮助将不胜感激:)

【问题讨论】:

    标签: node.js discord discord.js


    【解决方案1】:

    您可以回复消息或在与消息相同的频道(DM频道)中发送消息

    if(message.channel instanceof Discord.DMChannel && !message.author.bot) {
      return message.reply('You can not message me through DMs')
    }
    

    或者

    if(message.channel instanceof Discord.DMChannel && !message.author.bot) {
      return message.channel.send('You can not message me through DMs')
    }
    

    【讨论】:

    • 我试图这样做,但它似乎在做自己的循环。这些消息似乎在无限循环中重复。关于为什么会发生这种情况的任何线索?
    • 您只需要确保它不会响应机器人消息,我建议您将if (message.author.bot) return 放在message 事件的顶部。但出于这个问题的目的,我相应地编辑了我的答案
    猜你喜欢
    • 2018-11-19
    • 2020-11-19
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 2020-05-31
    • 2019-07-18
    • 2021-03-28
    • 2021-06-06
    相关资源
    最近更新 更多