简体   繁体   English

需要帮助修复 Discord Bot 命令

[英]Need help fixing a Discord Bot command

I'm making a >bean {user.mention} command, which the bot would respond with {user.mention} has been beaned, I want the responce to not ping the user: but just say the users username and hashtag (ex. Example#1234).我正在制作一个 >bean {user.mention} 命令,机器人会用 {user.mention} 响应它,我希望响应不对用户执行 ping 操作:而只是说出用户的用户名和主题标签(例如。示例#1234)。

Here is my code (node.js v12):这是我的代码(node.js v12):

  if (message.content.startsWith('!bean ')){
    message.channel.send('${user} has been beaned!')
  }
})

Read docs阅读文档

Coming to your question来回答你的问题

client.on("message", message =>{
    if(message.content.startsWith('!bean')){
        let target = message.mentions.users.first()
        if(!target) {
            message.reply(`Mention a user to bean!`)
        } else {
        message.channel.send(`${target.username} has been beaned`)
    //.username returns their username like 'Wanda' & .tag returns their tag like 'Wanda#1234'
    }
    }
})

Some things you can change to make your future coding organised您可以更改一些内容以使您将来的编码井井有条

• Use a command handler • 使用命令处理程序

2 things you must change 2件事你必须改变

• Update to discord.js v13 since v12 is deprecated • 更新至 discord.js v13,因为 v12 已弃用

• Update your node to v16 or higher • 将您的节点更新到 v16 或更高版本

In-case you need help knowing initial setup changes, read the guide如果您需要帮助了解初始设置更改,请阅读指南

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

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