javascript 如何让机器人提及频道?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49353929/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 08:32:29  来源:igfitidea点击:

How do I get a bot to mention a channel?

javascriptnode.jsdiscorddiscord.js

提问by Pruina Tempestatis

I am making a welcome message but I can't seem to make it say the rule channel. I want the bot to say #rules and make it so you can click it to go to the rules channel. I know you can do this with a normal user, but I want to do it with my bot. Every time I try, it can't be clicked like a normal player. I've tried doing #rules, <#channelID>, and other stuff. None of them are clickable.

我正在发送一条欢迎信息,但我似乎无法说出规则频道。我希望机器人说 #rules 并设置它,以便您可以单击它以转到规则频道。我知道你可以用普通用户来做这件事,但我想用我的机器人来做。每次尝试都不能像普通玩家一样点击。我试过#rules、<#channelID> 和其他东西。它们都不可点击。

回答by André

You need to send a GuildChannelfor the channel name to be clickable.
You can achieve this by finding the channel in guild.channels
This returns a Collection, which you can filter.
If you have an ID (easier):

您需要发送一个GuildChannel频道名称才能点击。
您可以通过在guild.channels
This Return a Collection 中找到频道来实现这一点,您可以对其进行过滤。
如果你有身(更容易):

var message = "Make sure to check the rules at " + 
  message.guild.channels.get('channelID').toString();

If you want find the channel by ID (might break if you have multiple channels with the same name):

如果您想通过 ID 查找频道(如果您有多个同名的频道可能会中断):

var message = "Make sure to check the rules at " + 
  message.guild.channels.find(channel => channel.name === "rules").toString();


EDIT:

编辑:

Much easier way: in Discord mention the channel and put a \(backslash) before the channel name \#rules. You'll get something like <#channelID>.
Use that like this: var message = "Make sure to check the rules at <#channelID>";

更简单的方法:在 Discord 中提及频道并\在频道名称之前放置一个(反斜杠)\#rules。你会得到类似的东西<#channelID>
像这样使用:var message = "Make sure to check the rules at <#channelID>";