Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

node.js - Discord.js - How can you make a bot print the name of a server through the server ID?

I'm making a command that when kicked/banned from a server, it DM's you "You've been kicked from [SERVERNAME]:", but I am unsure how to make it print the name of the server, along with the server icon.

Would someone be able to help me with this?

question from:https://stackoverflow.com/questions/66068291/discord-js-how-can-you-make-a-bot-print-the-name-of-a-server-through-the-serve

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

1 Answer

0 votes
by (71.8m points)

Client#guildBanAdd

The following event, according to the documents, returns two parameters:

  • Guild: The guild the spoken of ban occurred from.
  • User: The user who was banned.

We can take this knowledge and use it in the purpose of DMing the banned user with the guild's name, and using the icon as well.

client.on('guildBanAdd', (guild, user) => {
  user.send(`You were banned from ${guild.name}!`, {
    files: [guild.iconURL()]
  })
})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...