阅读标题,如果有人可以帮助我,我会很高兴
例如,messages.mentions.first()。像那样,提到的用户名有什么用吗?
最好的方法是使用message.mentions.users.first()
,因为这实际上会给您消息中提到的第一个用户。 (message.mentions不是collection)。如果未提及任何用户,则第一个将显示为undefined
,因此您可能需要进行检查。拥有用户后,您将要访问username
属性。
示例:
// Assuming we just need a message event
client.on('message', (message) => {
const user = message.mentions.users.first();
if (user === undefined) {
return; // Do not proceed, there is no user.
}
const name = user.username;
// Do stuff with the username
})