I'm having a bot that accepts DM from users (There should be at least one mutual server).
Now is it possible for the users to perform a DDOS or any similar type of attack. Or simply can they spam the bot and make it unavailable for normal users?
How can I tackle this as I couldn't find any slow-mode delay for a dm_channel and is only available for text channels. I have used discord.py.
Is there a way to make something similar to slow mode delay in a DM? I mean users shouldn't be able to send multiple messages at once to the bot as DM, and should wait for the specified amount of time (or any decent amount of time).
DDOS can happen anywhere, but it will happen to discord first before the bots can "chat-command-spam" your bot. Which you don't really have to worry about getting DDOS'ed by a few spammers (even with a few gaming computers, spamming your bot commands in discord dm at the same time without getting noticed by discord, it won't affect your bot that much). There are cases like if you have a really expensive command in your bot, and people are frequently calling the command, then you can put a cooldown in your code for the expensive command.
Related
Here my Code:
#bot.event
async def on_disconnect():
channel = bot.get_channel(1064939978569822309)
await channel.edit(name="Bot status: 🔴")
I dont have any errors but nothing happends if the bot disconnect.
Can anyone help me?
I reinstall the library.
According to discord.py's documentation. on_disconnect() is used for when the bot cannot connect to the discord server.
If the bot cannot connect to the server, it would not be able to get the discord channel (think about it, if you can't connect to discord you would not be able to send any message at all, much less editing the channel).
on_disconnect() is probably more for the usage on the local side of things (e.g. printing out logs to check why the bot cannot connect to the discord server) rather than to update the bot's status.
It is not possible to do this automatically, unless you have another bot monitoring this bot (which is not really viable as both bots could be down at the same time).
If you want to handle cases where you have to shutdown the bot (for maintenance purposes, as an example), you can instead have a function (an idea is you can have it as a discord command that can only be run by the bot's owner) to edit the channel before going offline.
I have been trying to update my discord bot to discord.py v2.0 and wanted to switch over to slash commands and cogs. When trying different techniques of achieving this I once used py-cord. I created a test command called latency and it worked but since I struggled with py-cord I uninstalled py-cord and found a new technique. The problem is that the latency (my py-cord) command is still there on the list where you can choose what slash command to use and so I wonder how do I remove this from the bot command selection?
When working with slash commands, the discord API registers and deregisters the slash commands on their own servers, and then sets up hooks for your bot.
This means that, when the bot connects, it sends an API call to discord to tell it what commands it has, after which you need to wait for Discord to register that properly. They don't guarantee to do that instantly, not for deletion nor registration.
So, in short, you don't remove it from the bot section; you wait until Discord does that for you. They guarantee that they do that in 24 hours of your bot being online, but, realistically, it's usually done in less than 2.
You can set debug_guilds if you want to register commands faster, which would allow you to have a few guilds (servers) that would get updated first, usually quite close to immediately. However, from my own experience, that helped very little for deletion, as Discord usually took its time for that.
One more advantage of debug_guilds is that, when passed, any new or deleted commands are only registered for those specific guilds, allowing you for more free testing. However, it is not perfect, as changed excising commands are of course still run trough your testing bot.
Instead, my advice would be this: Create a second bot, and use that one for testing stuff. Once it's done, you can update the new bot with the verified code. This way, no one gets annoyed at multiple registered commands and all that! If you know how to use git: just run one bot on the main branch, and the other on the development branch. :-)
I hope this helps! :-)
I made a telethon program that parses messages from the list of channels into telegram, but the problem is that the parser reacts to the post only when it comes to the account with which I originally logged in. Sometimes posts come with a delay due to the fact that I'm not sitting in the telegram, but you need to make sure that you respond to messages as quickly as possible. How can this be done?
Hey so ive been trying to make a selfbot and hopefully slowly learn python along the way. I ve gotten far enough to do it in one account but i want to do it from multiple accounts controlled by a master account with commands and command prefixes. This video shows what i am trying to replicate, just i want to do it in server as well and not necessarily spam that much just one set of message from each account is good enough. https://www.youtube.com/watch?v=1N6cR-FIJgE This is the video. How do i convert the code to use multiple tokens and control those accounts with a master account. https://github.com/casrfgd2/discod - this is the code
Self bots are against Discord's Terms of service and can get your account or in this case multiple accounts banned
What you could do is make a discord bot and use it to the mass dm (which is also kind of against the terms) with just one discord account
To use multiple bots with the same code you could fork the repository per bot and put the different token in your env file every fork
I am making a discord bot and I want to know how I can add a basic implementation of seeing which users are active daily on the server and how long they're active. The definition of active is not accurate but it could be if they sent a message in the group throughout the day. What would be the code to implement something like this in my discord bot? Thanks a lot!
Checking to see who has sent a message is simple enough to do,
You could use the on_message function to see who has sent a message in your server, using this method you could get the user and append them to a list and then delete the list every so often (eg. daily, or you could wait for an admin to call a command within the server).
The positive side of this method is that you can control what counts as active, for example you could also use on_reaction_add and its opposite.
This is a simple example of a bot that checks the users that have sent messages in the server and adds them to a list. Note: This script doesn't delete the list, meaning that members will be permanently in the active list, you should be able to implement this in your code fairly easily.
import discord
client = discord.Client()
activeMembers = [] #We create an empty list to hold the users that have been active
#client.event
async def on_message(message):
if message.author not in activeMembers:
activeMembers.append(message.author)
client.run("YOUR TOKEN HERE")
I've missed out some things that you probably have if you've started your bot already. If you haven't, fear not as there are multiple articles and tutorials on creating a bot.
The problem is that you want to see how long a member is active on your server, so what you could do is log the times they have sent messages, and then calculate the time they've been active on the server by deducting one value for another. This isn't accurate as you've stated, but is the best solution in my mind. The biggest problem here is that someone could send a message early in the morning and then go off about their day and then send a message at night, this would mean that the bot would think they are active for many hours (seeing as their first message was sent much much earlier) when in fact they are not. A simple workaround is to check every users last message time, and use a threshold time (if you will) to see who is no longer active.
For example, if someone sent their last message half an hour ago, they would no longer be seen as active and their total time would be calculated based on their first message and their last message. Their data would then be purged, so that if they send a message much later on, the bot doesn't use their first message of the day to calculate how long they've been on for.
Looking back on this this explanation is a bit shoddy, so Ill try quickly summarise it in a timeline sort of fashion.
A user sends a message in a channel and the bot records their id and the time they sent it -> They send another message five minutes later, the bot records the same data -> The user hasn't sent a message in half an hour (example of a threshold time, you could make yours shorter or longer) and the bot calculates their time and removes their message times. This time is then added to their total time.
This can be done using .create_task() where you pass in a function to run in the background. The function you would pass would regularly check when users sent their last message.
Should you want to define active as things other than reactions or sending messages, visit discord.py to find out the different things you can do.
Best of luck,
Ben