【问题标题】:Discord Bot Mention a user in dmDiscord Bot 在 dm 中提及用户
【发布时间】:2020-07-27 01:55:21
【问题描述】:

所以我希望机器人 @ 他正在与之交谈的用户,因为 ${member}(我在 youtube 上看到)不起作用,所以我想问我必须写什么,以便他写“你好 @(用户名)...”请记住,他是作为 dm 写的。

const Discord = require('discord.js');
const { prefix, token } = require('./config.json');
const client = new Discord.Client();

client.on('ready', () => {
    console.log('This Bot is online!');
})

client.login(token);

client.on('guildMemberAdd', member => {
    member.send('Hello ${member}, welcome to the PotatoHost Server!');
});

【问题讨论】:

  • Java != JavaScript ;) 您可能想要更改标签!

标签: javascript bots discord mention dm


【解决方案1】:

问题不在于会员,而在于client.login(),如果代码应该总是在最后!

我希望这会对你有所帮助。祝你有美好的一天!

编辑:另外,有些成员已经锁定了 dm,所以你应该使用 try-catch 功能,如果你遇到错误,请在聊天中发送欢迎消息。

try-catch 函数是这样工作的:

try{
member.send("message here")
}catch(error){
member.guild.channels.get("here the Id of the channel you want to send the welcome message in").send("message here")
}

如果您不喜欢在服务器的频道中发送消息的想法,请改为:

console.log(error)

【讨论】:

  • 所以现在一切正常,除非我在我的测试帐户上禁用了 dm 选项并加入我的测试服务器,机器人没有在频道中发送欢迎消息
  • 这个机器人在线! (node:14224) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send messages to this user at RequestHandler.execute (C:\Users\nicos\OneDrive\Documents\Discord Bots\PotatoHost Bot\node_modules\discord.js\src\rest\RequestHandler.js :170:25) 在 processTicksAndRejections (internal/process/task_queues.js:97:5) (node:14224) UnhandledPromiseRejectionWarning: 未处理的承诺拒绝。此错误源于在没有 catch 块的情况下抛出异步函数内部,或拒绝未使用 .catch() 处理的承诺。
  • 要在未处理的 Promise 拒绝时终止节点进程,请使用 CLI 标志 --unhandled-rejections=strict(请参阅 nodejs.org/api/cli.html#cli_unhandled_rejections_mode)。 (拒绝 ID:1)(节点:14224)[DEP0018] DeprecationWarning:不推荐使用未处理的承诺拒绝。将来,未处理的 Promise 拒绝将使用非零退出代码终止 Node.js 进程。
【解决方案2】:

我刚开始时遇到了同样的问题,这应该可以帮助您解决问题:

client.on("guildMemberAdd", async member => {
const dmErr = false;
try {
await member.send()
} catch (error) {
dmErr = true;
} if (dmErr === true) {
member.guild.channels.get("Id of the channel here").send()
}
}); 

【讨论】:

  • (node:14224) UnhandledPromiseRejectionWarning: TypeError: 赋值给常量变量。在 Client. (C:\Users\nicos\OneDrive\Documents\Discord Bots\PotatoHost Bot\index.js:18:15) 在 processTicksAndRejections (internal/process/task_queues.js:97:5) (节点: 14224) UnhandledPromiseRejectionWarning:未处理的承诺拒绝。此错误源于在没有 catch 块的情况下抛出异步函数内部,或拒绝未使用 .catch() 处理的承诺。要在未处理的 Promise 拒绝时终止节点进程,请使用 CLI 标志 `
  • --unhandled-rejections=strict`(见nodejs.org/api/cli.html#cli_unhandled_rejections_mode)。 (拒绝 id:1)(节点:14224)[DEP0018] DeprecationWarning:不推荐使用未处理的承诺拒绝。将来,未处理的 Promise 拒绝将使用非零退出代码终止 Node.js 进程。
  • 给我一张index.js或者整个代码的照片,看不到代码我解决不了
  • 你有什么不和还是什么,因为我不能在这里发照片,我不能在不到 5 cmets 的时间内编写整个代码
  • 在这里联系我:AptaLinny#2327
猜你喜欢
  • 1970-01-01
  • 2021-10-24
  • 2021-02-07
  • 1970-01-01
  • 2021-06-04
  • 1970-01-01
  • 1970-01-01
  • 2020-09-02
  • 2020-04-18
相关资源
最近更新 更多