简体   繁体   English

如何让 Discord.js 当我们提到(@)机器人时,机器人以本地图片响应?

[英]How to make Discord.js Bot responds with local picture when we mentions(@) the bot?

I am a newbie to JavaScript. I want to make my discord server's bot responding with local picture on my computer while anybody mentions(@) it.我是 JavaScript 的新手。我想让我的 discord 服务器的机器人在有人提到 (@) 它时在我的计算机上响应本地图片。 I have tried multiple methods,我尝试了多种方法,
this is the one I follow the documentation:这是我遵循文档的那个:

client.on('message', (message) => {
 if (message.mentions.has("My Bot's ID")) {
  const attachment = new MessageAttachment('./images/image1.png');
  return message.channel.send(`Hi ${message.author},`, attachment);
 }
});

This one failed, as well as a few older version methods I tried.这个失败了,我尝试了一些旧版本的方法。 Some of them not even operate, so I deleted them.有的连操作都没有,所以我删掉了。

Also, I can't find any other materials besides the documentation for the version(12.3.1).另外,除了版本(12.3.1)的文档外,我找不到任何其他材料。

MessageMentions is an object. You are looking for the MessageMentions.users Collection. MessageMentions是一个 object。您正在寻找MessageMentions.users集合。

client.on('message', (message) => {
 if (message.mentions.users.has("My Bot's ID")) {
  // message.mentions.users
  const attachment = new MessageAttachment('./images/image1.png');
  return message.channel.send(`Hi ${message.author},`, attachment);
 }
});

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

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