javascript - 如何在 Discord.js 中更改带有消息的用户的昵称?

标签 javascript node.js discord.js

我尝试在 Discord.js v12 中更改用户的昵称,但由于某种原因我收到错误:

类型错误:fn 不是函数

这是我的代码:

message.guild.members.cache.find(message.author.id).setNickname(username)

message 只是来自 .on("message")Message 对象。

最佳答案

.get()不同,.find()接受一个函数,因此您可以像这样使用它:

message.guild.members.cache
  .find(member => member.id === message.author.id)
  .setNickname()

您还可以使用 .get() :

message.guild.members.cache
  .get(message.author.id)
  .setNickname()

或者更好的是,使用 .fetch() :

message.guild.members.fetch(message.author.id)
  .then(member => member.setNickname())

或者,您可以使用 member 从消息本身获取成员。代表消息作者作为公会成员的属性:

message.member.setNickName()

关于javascript - 如何在 Discord.js 中更改带有消息的用户的昵称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66892781/

相关文章:

javascript - 如何在Google Maps API中组织数千个数据点?

android - 当应用程序被终止时未收到通知 FCM 与 Firebase 的 Cloud Functions

javascript - Discord.js 修复了 V14 的 TypeError [ClientMissingIntents] : Valid intents must be provided for the Client but it is still having the same problem

javascript - Vue/Nuxt.js - 计算嵌套 JSON 值的总值

javascript - 在没有反应插件的情况下使用 eslint-config-airbnb

javascript - "Obect has no method"从回调函数中调用其他函数时

javascript - Node.js 'require' 不需要命名空间即可访问其他文件

javascript - 为什么我无法使用 Typescript/node.js 导入模块?

javascript - 重叠命令?

javascript - DiscordJS Canvas 附件未完全发送?