How to make my discord.js bot show how many servers it is in as it's status - discord.js

I'd like to have my bot have a status that says how many servers it's in.
For example, in 6753421 guilds. I figure you'd make a separate section of code and add ${} to the status with the name of the function in it.

You need to use client.setActivity() and then use the client.guilds.cache.size value.
For example:
client.setActivity(`serving ${client.guilds.cache.size} servers`);

Related

Need custom command options for discord bot without using slash commands

Can I attach slash command options to a custom command like "?help" and not "/help"?
I’m not entirely sure that I know what you mean, but I’ll try to answer.
?help is something we call a message command. It’s basically a message and is received as a messageCreate event. The bot then filters all message events to only respond to those with the specified prefix (in this case “?”). The only thing a user can submit via a message is the message content, a string, and attachments, which are files. You can access that via .content. You can make the user submit arguments by typing space and then e. g. writing a category name (?help moderation) which you could then recognise with <Message>.content.split(“ “);.
/help is, when registered as such, a slash command (interaction). When received, the interactionCreate event is called. When you register a slash command, you can add options such as string, integer, member and so on. These are registered beforehand and only in because of that, discord knows what options to give the user. And yeah, after that, you can access these options via the interaction.
To sum up (if I understand you correctly), you can’t attach (slash command) options to message commands because they are handled differently by discord. You can, however, utilise spaces to use these options. (Slash Commands are not using spaces but rely only on these options.)
I hope this helps.

Clickable command in text Discord

I saw a YouTube video that shows you a way to display a "slash command" on Discord (see Image 1)
by sending "</any text:0>" (not clickable). I tried with any number at the end and its still working. So I tested </a slash command in my bot:MY BOT ID> and it was still working but it is not clickable.
Does anyone know a way to make a clickable slash command like in verified Discord bot profiles?
I am not sure it's possible but if someone knows how to do it.
Thanx in advance.
You can't control the 'Try my commands' section from appearing on your bot's profile. Discord will generate that section for your bot after a while of your bot being online & used.
In order to put clickable slash command buttons as you've shown you need to use the application command ID, not the bot id. You can find that by clicking on the prompt:
You can then take that ID to form </fast:972289487818334212>, which will be a clickable form of slash command.
Please note that slash command ids are changed randomly and frequently on Discord's end.
For sub-commands, you can do as such:
</cool-bot settings:2046185065514240342>
The command ID can be found under message.data.id, when your server receives a command.

Is it possible to DM someone with their user ID?

I want to make it so you can pass someone's user ID into some args instead of mentioning them.
I am not sure how to pass it through that way, I have only figured out how to do it with mentioning them.
How can I do this?
Sorry I have not given any code but could someone be nice to tell me how to do it please?
I am assuming that you have defined args and client already. If you named this variables differently, just change the names.
This is how you could make it:
let user = client.users.cache.get(args[0]);
user.send("Hello World!");
Usage:
!dm <User ID>
This code can put in your code without client or args, just need message
message.client.users.fetch(message.content).send("Hello there!");

Sub commands in discord.py?

I’m writing a simple bot for a discord server, and I’m trying to explore a few different ideas and two of them require some kind of response and sub command based on responses. I want people to be able to poll something without it being done through reacting to a bots post. I’m unsure of how to go about this.
I’ll give one as an example.
Ideally, it could be structured something like this.
[initiate poll command] [poll name]
Then to respond, a user could do something like this:
[poll name] [yes/no]
Or for a pseudo-code example:
!start_poll Lets_do_this
!lets_do_this yes
Then if it meets a certain threshold of yes’s, a sub command would execute.
My idea would be to create a dictionary. Whenever someone starts a poll, you would add two keys to the dictionary: "[name]_yes", and "[name]_no". Each key would have an empty list. I would then use a command such as "!vote [poll] [yes/no]" to simplify the coding, and whenever somebody voted, I would add their discord ID to the corresponding list. It would be a good idea to check if their name is already on a list, however. Then if you wanted, you could take the size of each list to see how many people have voted for each. The dictionary would end up looking something like:
{
'lets_do_this_yes': ['Bob', 'Suzy'],
'lets_do_this_no': ['Dan'],
'lets_do_this_instead_yes': ['Dan','Joe'],
'lets_do_this_instead_no': ['Suzy']
}
Note: I haven't used discord.py, but I have experience with Python and Discord.JS
Hopefully this works for you.
Edit: The result example above would not actually have their Discord name, but rather their Discord ID, as that is unique to them where as their name can be changed.

Problems with sorting emails

I am wresting to sort email messages which I got using this api
https://developers.google.com/gmail/api/v1/reference/users/messages/list
Does anybody know how gmail api send this messages?
Do they send messages in order?
Thanks
Go to Users.messages.list and Execute the Try-it. You will notice that the threadIds of messages appear in descending order with the newest one appearing on top. Also confirmed in this SO post.
I recently looked into the same issue and wrote a short python prototype - feel free to take a look, it is publicly available on Github: https://github.com/jan-janssen/pygmailsorter
As #reyanthonyrenacia already pointed out the key part is using Users.messages.list, I then combine this with Users.messages.get to receive the full message and finally add or remove the label using the Users.messages.modify action.

Resources