Tim*_*arn 5 javascript bots discord
我搜索了很多答案,但我没有找到和/或理解它。如何在此代码中提及消息作者?
它只是说:
${user.username} 乒乓球
但我想要:
@(消息作者用户名) pong
实际上,模块中已经有一个非常简单的函数discord.js可以为您提供该函数。
${user.username} pong您可以不写,而是message.reply('pong')...但是这会将其格式化为@user, pong. 所以加了一个逗号。
另一种方法是简单地执行message.channel.send('<@' + message.author.id + '> pong');,以便不使用逗号。但我更喜欢message.reply只是因为它可以减少打字的次数,哈哈。
为了使 alt 方法更接近您的代码,您可以考虑设置usertomessage.author而不是,message.author.name因为这只是昵称对象。然后,从此,你可以简单地做message.channel.send(`<@${user.id}> pong`);
所以它应该看起来像:
const user = message.author;
return message.channel.send(`<@${user.id}> pong`);
Run Code Online (Sandbox Code Playgroud)
另一种方法:
const user = message.author;
return message.channel.send(`${user} pong`);
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!
| 归档时间: |
|
| 查看次数: |
15508 次 |
| 最近记录: |