DiscordJS -> Formatting message like server join - javascript

I'm working on an emote bot for our text chat channels. I have it kind of working. The goal is that if a user types something like:
~hug #user
The bot sweeps up the message, removes it, and then emotes to the chat room:
| Joe hugs Jane. Awww!
This is working, but I'm using embed with a red border on the left side to make it look special. However this shows as a message from the bot, with the avatar picture, bot name, and such. What I'd like to do is have emotes show up without the bot name and such, like the announcement format when someone joins a server, etc.
Any advice on how to send a message formatted like that to a channel?

Unfortunately sending any messages that look like system messages, such as RECIPIENT_ADD, RECIPIENT_REMOVE, CALL, CHANNEL_NAME_CHANGE, CHANNEL_ICON_CHANGE, PINS_ADD or GUILD_MEMBER_JOIN is not possible using a Discord Bot.
This is a limitation of Discord itself and not a limitation of discord.js
You could, however, try to achieve a similar-ish looking result by using a webhook with a blank Avatar and Username.
message.channel.createWebhook('/*Webhook Name*/', "/*Webhook Avatar URL*/")
.then(w => w.send("your message here"));

Related

Get discord bot server count in shields.io

I'm trying to use shields.io to get my Discord bot's server count to render it on my website.
I tried to search for resources online; nothing helped. It would look like this for example: https://img.shields.io/badge/servers-10-orange

Messages leaderboard issue discord.js

How are you?
I'm coding a Discord bot and I'm making a message leaderboard command, which displays up to 15 members with most messages (quick.db package to store data). Basically, It's alright when I run the code, but when someone who has so much messages and should appear in the leaderboard leave the server, it returns an error when I try to get the members tag and undefined in the message.
Is it possible to hide the user or delete them from the database?
What have I tried to solve the problem?
I tried to read Discord docs. and quick.db package to see if I can delete the user when they leave (using guildMemberRemove event), but what if they get back to the server?
οΎ 
A better way is to delete user(lefted)* data from database once user left the server in guildMemberRemove event

Discordjs how to make a join message for any server?

I know you can do it like this
bot.on('guildMemberAdd', member => {
member.guild.channels.get('channelID').send("Welcome"); });
But then you have to specify a channelID.
Welcome Channel
All members join through this link onto the welcome channel. Is there a way that discordjs sends a join message where ever the user got invited? Example: A join link for general so the welcome message is in general.
Thanks for the help :)
The guildMemberAdd event only returns a GuildMember object which doesn't seem to include a reference to the invite used. You can fetch all the generated invite links and guess which one was used, but I wouldn't recommend this option.
Here are three solutions I can think of:
Use the System Message Channel
This channel can be defined in the server settings without enabling the "Random welcome message". You can find it in Guild.systemChannelID.
https://discord.js.org/#/docs/main/stable/class/Guild?scrollTo=systemChannelID
With public bots, make this setting configurable by an admin
You can make your bot respond to a command that will allow an admin to select a channel, either by selecting the channel where the command was sent, or prompting a list of channels. This is not the most straightforward solution to implement, but this is the best in terms of UX for your users.
With private bots, hardcode the channel ID
This one will be the easiest to implement if your using your bot privately in one server or a limited number of servers.
Go into Discord settings
Appearance
Toggle "Developer mode" in the Avanced section
Then right click on the desired channel, and Copy ID
there is a event in the Client() class that called guildMemberAdd. It will return a GuildMember class that will store all informations about the newly joined member!
If you bot is private bot
then you can simple hard code your bot, by enable the developer mode and right-click on the specific channel that you want your bot send welcome messages to, chose get ID and then paste the copied ID to member.guild.channels.cache.get("THE_ID") and then simple send the message.
client.on('guildMemberAdd', member => {
const channel = member.guild.channels.cache.get("CHANNEL_ID"); // Getting the channel
if(channel){ // Checking if the channel exist
channel.send(`Welcome ${member} to ${member.guild.name}`); //Send the message
}
Else if your bot is public bot
Then you will need a setup command to helps others server owners setup their welcome message function with your bot.
You should need a database (google it, if you don't know) to store channel's IDs, then get the channel's ID and do the same thing that I mentioned before!

How do i make my discord bot write like this box?

I've been looking for some discord bots. These days, i found one that make this:
I'll explain because the bot it's in Portuguese.
In the yellow part, the bot says: "Sugested by #member
In the light blue, the bot says the command to the members, (it's a bot that rewrite the messages, example: !sugest I would like marshmallows.)
In the dark blue, the bod auto add some roles.
How do i make my discord bot write in a "box" like that ?
Those are called Discord embeds. Take a look at the example in their documentation:
https://discord.js.org/#/docs/main/stable/examples/embed
const Embed = new Discord.MessageEmbed()
.setColor("YELLOW")
.setTitle(`Suggested by <#${message.author.id)>`)
.setDescription("``TEXT GOES HERE``")
.setFooter("!sugest I would like marshmallows.")
message.channel.send(Embed)
message.react('πŸ‘');
message.react('πŸ‘Ž');
The Embed you are trying to copy is probably from a Starboard bot so you'll need some more coding to get it to send a message to a specific channel

Delete message that have been sent by the Discord Bot [Discord JS]

I want to delete some message that my bot has send, to a text channel, when a user writes a command. I just found info about deleting a msg after a certain time. But nothing about deleting a particular msg.
Also i must say that it will a better option to my code to delete the message with the messageID or something like that. Not the message obj.
Do you guys know a way to do that?

Categories

Resources