如何返回公会的所有者名称

编程入门 行业动态 更新时间:2024-10-23 15:16:55
本文介绍了如何返回公会的所有者名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是我遇到问题的代码片段:

This is the piece of my code where I'm having the problem:

const guild = client.guilds.get('500170876243935247'); message.channel.send(guild.owner);

我希望它返回所有者的名字,相反,它在控制台中说这是一条空消息.我已经运行了 guild.owner 和 console.log ,显然它显示的是来自行会的所有数据,表情符号,会员ID,最后显示了所有者的用户详细信息,操作方式我要分别显示它们吗?

I expected it to return the owner's name, instead it says in the console that it's an empty message. I've run guild.owner with console.log and apparently it's displaying all data from the guild, emojis, member's IDs and at the end, the owner's user details, how do I display them separately?

记录下来,这是我认为需要重点关注的最后一部分:

For the record, this is the last part that I think is the focus that I need:

user: User { id: '317669302549XXXXXX', username: 'Flicker', discriminator: 'XXXX', avatar: 'a_161cc6f5d0466f7afd9a73dc2eba159d', bot: false, lastMessageID: null, lastMessage: null }, joinedTimestamp: 1539320429681,

推荐答案

将用户转换为字符串时, User.toString() 方法会自动调用:将User对象转换为提及内容,例如 @用户名.但是,如果您执行 message.channel.send(User),它将不会调用 User.toString() ,因此discord.js将留有无法发送的对象(有效对象的示例: message.channel.send( RichEmbed )),因此邮件为空.

When you convert a User to a string, the User.toString() method is automatically called: that converts the User object into a mention, like @username. But if you do message.channel.send(User) it will not call User.toString() and so discord.js will be left with an object that it can't send (example for valid object: message.channel.send(RichEmbed)), and so the message will be empty.

为避免这种情况,您可以尝试使用 User.tag :这样,您还可以避免每次有人使用该命令时都收到通知.如果您不介意收到通知,则可以在可能的情况下使用第一个,否则可以使用第二个.这是一个示例:

To avoid this, you can try to replace the mention with something like User.tag: with this you also avoid being notified every time someone uses that command. If you don't mind being notified you can use the first one when possible, otherwise the second one. Here's an example:

const guild = client.guilds.get('500170876243935247'); message.channel.send(message.guild.member(guild.owner) ? guild.owner.toString() : guild.owner.user.tag); // if the user is in that guild it will mention him, otherwise it will use .tag

更多推荐

如何返回公会的所有者名称

本文发布于:2023-10-16 05:35:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1496648.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:所有者   公会   名称

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!