为什么Discord.js v13机器人@提及用户时无法触发ping通知?
问题根因
Discord.js v13 自定义allowedMentions配置时会覆盖默认的提及规则,你当前的代码仅开启了回复场景下的用户提及权限,没有配置允许普通内容中的用户提及,因此消息里的<@${message.author.id}>只会显示为提及文本,不会触发实际的ping提醒。
修复方案
- 方案一:明确指定允许提及的用户ID列表
await message.guild.channels.cache .get(<SOME_ID>) .send({ allowedMentions: { repliedUser: true, users: [message.author.id] }, content: `Welcome <@${message.author.id}> this is your channel` });
- 方案二:配置允许的提及类型,适配所有同类型的提及
await message.guild.channels.cache .get(<SOME_ID>) .send({ allowedMentions: { repliedUser: true, parse: ["users"] // 允许所有用户提及,如有需要可追加"roles"、"everyone" }, content: `Welcome <@${message.author.id}> this is your channel` });
注意:如果需要提及@everyone、@here或者角色,机器人需要在对应频道拥有
Mention @everyone, @here, and All Roles权限,普通用户提及无需额外权限。
内容的提问来源于stack exchange,提问作者Lord Reptilia
相关产品推荐
相关产品推荐

