【问题标题】:discord.js getting the bot to execute "@(person who typed the command)"discord.js 让机器人执行“@(输入命令的人)”
【发布时间】:2021-05-23 10:46:41
【问题描述】:

我是 discord.js 的新手,想让机器人回复发送命令的人。例如:

Person1: !hello
Bot: Hello, @Person1

通常,我会创建这样的命令:

ma​​in/index.js

if(command === 'cmd'){
        client.commands.get('cmd').execute(message, args);

cmd.js

module.exports = {
    name: 'cmd',
    description: 'example command',
    execute(message, args){
        message.channel.send('this is a command');
    }
}

如果可以以这种格式进行,那将非常有帮助。再次,为我缺乏理解而道歉,这对我来说仍然很新。谢谢。

【问题讨论】:

标签: javascript discord discord.js


【解决方案1】:

您可以简单地使用message.author 来提及消息的作者,如下所示:

execute(message, args) {
  message.channel.send(`Hello, ${message.author}!`);
}

【讨论】:

    猜你喜欢
    • 2020-08-21
    • 2021-04-18
    • 2021-08-04
    • 2021-06-02
    • 2020-11-09
    • 2021-06-02
    • 2021-10-23
    • 2021-07-27
    • 2021-11-21
    相关资源
    最近更新 更多