Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
477 views
in Technique[技术] by (71.8m points)

javascript - How do I get a bot to mention a channel?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

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

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>";


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...