这是我遇到问题的代码片段:
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更多推荐
如何返回公会的所有者名称
发布评论