简体   繁体   English

discord.js 让机器人执行“@(输入命令的人)”

[英]discord.js getting the bot to execute "@(person who typed the command)"

I am new to discord.js and wanted to make the bot to reply to the person who sent the command.我是 discord.js 的新手,想让机器人回复发送命令的人。 For example:例如:

Person1: !hello
Bot: Hello, @Person1

Usually, I would create my commands like this:通常,我会像这样创建我的命令:

main/index.js主/index.js

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

cmd.js cmd.js

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

If it's possible to do it in this format, it would be really helpful.如果可以以这种格式进行,那将非常有帮助。 Again, apologies for my lack of understanding this is still very new to me.再次,为我缺乏理解而道歉,这对我来说仍然很新。 Thanks.谢谢。

You can simply use the message.author to mention the author of the message like this:您可以简单地使用message.author来提及消息的作者,如下所示:

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

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM