简体   繁体   English

对提到的用户进行命令回复

[英]Making a Command Reply with a Mentioned User

So I'm trying to make a hug command.所以我试着发出一个拥抱的命令。 I want it to be used like "/hugs @user" and the bot replies with "@author sent a hug to @user.", When I use the code below.我希望它像“/hugs @user”一样使用,当我使用下面的代码时,机器人会回复“@author 向@user 发送了一个拥抱。”。 I just set it to try to reply with the mentioned user but it doesn't work.我只是将它设置为尝试回复提到的用户,但它不起作用。 I have tried setting it to a variable as well and putting "message.mentions.users.first()" in a variable too.我也尝试将其设置为一个变量,并将“message.mentions.users.first()”也放入一个变量中。 It seems to work for other people after what I've looked up but for some reason nothing is working for me.在我查找之后,它似乎对其他人有用,但由于某种原因,没有什么对我有用。 The bot does not reply at all after mentioning a user.提到用户后,机器人根本不回复。 No errors pop up either.也没有错误弹出。

    if (words == `${prefix}hugs`) {
        message.channel.send(`<@${message.mentions.users.first().id}>`);
    }
if (words == `${prefix}hugs`) {
    message.channel.send(`${message.author} sent a hug to ${message.mentions.members.first()}`);
}

You don't have to get the id, you can just use the member.您不必获取ID,只需使用会员即可。 It will return the first member mentioned in the message.它将返回消息中提到的第一个成员。

So the code works when made as a command file but for some reason only one person is allowed to use the command.因此,该代码在作为命令文件制作时可以工作,但由于某种原因,只允许一个人使用该命令。 I've deleted the file and rewrote it, changed the name, and everything.我已经删除了文件并重写了它,更改了名称,以及所有内容。 That was why i ended up putting it in the main function since it for some reason only lets one user use the command.这就是为什么我最终把它放在主要的 function 中,因为它出于某种原因只允许一个用户使用该命令。 It seems like the first person who used it originally is the only person allowed to use it.似乎最初使用它的第一个人是唯一被允许使用它的人。 Is there a way to erase that memory or something since it might've been from previous code that was messed up?有没有办法删除 memory 之类的东西,因为它可能来自以前的代码被搞砸了?

Here's my new current code这是我的新当前代码

module.exports = {
    name: 'hug',
    description: 'Used to hug everyone or mention a user to hug them specifically.',
    execute(message,args) {
        args = message.mentions.users.size;

        if (!args) {
            message.delete();
            return message.channel.send(`${message.author} gives a big ol' hug to everyone!`);
        }
        else {
            message.delete();
            return message.channel.send(`${message.author} sends love to ${message.mentions.users.first()} with a hug!`);
        }
    },
};

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

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