I'm looking for a way of handling a bot missing permissions. Like I remove it "send_messages" permission and I try to make it send a message.
Thing is i don't know how to do, I've been looking for this for hours, and i don't want to add a
if bot.has_permissions("send_messages"):
each time i want to do anything.
Also the purpose of this bot if to be on servers I am not on so editing guild's permissions is not an option.
Thanks
You could add a general error handler for the Forbidden error, which discord.py raises on a 403 Forbidden: Missing Permissions error. You need to unpack it first from the general CommandInvokeError before.
#bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandInvokeError):
error = error.original
if isinstance(error, discord.errors.Forbidden):
await ctx.send("Whatever you want to say here.")
Related
I am interested in the best practice for handling errors in the Google Action SYNC handler.
I see in the docs that I can return an errorCode in the SYNC response, however, none of the documented error codes seem to be compatible with the SYNC handler, only QUERY, EXECUTE, etc.
I see that the SYNC response must contain a userAgentId or the Action service deems it an invalid response, however, what happens when I am unable to authenticate the user and I am unable to determine and ID for them?
In that case, should I simply provide an empty string for that property?
Should I just response with an empty object {} in the response when I encounter an error?
Any info is helpful, thanks.
Of all the listed error codes, not all of them may make sense but some like relinkRequired could be useful.
More specifically for you, in the case that the authentication process fails that error should come from the OAuth link. Your account linking, when presented with an incorrect user, should fail at that point and not proceed with sending a SYNC response.
I'm trying to create a macro that sends a message to different channels in different servers every 8h but I can't figure out how to make it send a msg in a channel automatic (I'm trying to send the msg as soon as I run the py file) I have been searching for different example in the discord.py documentation but all the examples I found send a msg after a command) but I just want to know how do I make a discord selfbot send a message that has multiple lines to a channel and then I believe I can make it myself.
I know this should just be a comment but for the sake of making sure people will see this, I'm also posting it as an answer.:
Self-bots are 100% against the Terms of Service of the Discord API, you can have your account deleted for using one. https://support.discord.com/hc/en-us/articles/115002192352-Automated-user-accounts-self-bots-
Put this in your code
import time
#client.event
async def on_message(message):
await message.channel.send('Text Here')
time.sleep(28800)
and selfbots are against the tos and you can get your account deleted
I have a bot with which you have to verify yourself to be on our Discord server
(The verification takes place in the DM`s)
Recently we have the problem that certain members of our Discord cannot write to the bot.
Everyone allowed everyone to send a message to the person
Each of the people is on our Discord Server, allows the person to write messages and have not blocked the bot
The bot does not issue any error messages
We would be delighted to find a quick solution
Since you haven't provided any code snippets, logs or error messages, it's a bit difficult to assess your situation... but here are some basic troubleshooting steps that you could follow:
Remove and re-authenticate the bot into the server.
Double check that you have enabled DM's.
Check the console for any errors that could pertain to direct messaging issues with users in the server. (especially from successful DM's)
Try to notice any differences between the users in the server who are
able to message the bot, versus those who cannot.
Ensure the bot isn't running more than one instance. (i.e. you might
have more than one bot running on the same token!)
I highly recommend giving more detail, because usually a question pertaining to broken/lost functionality would usually attach code or error logs to help diagnose the issue.
Okay, the problem is that you either didn't enable DMs or the bot is not in the server.
Otherwise, this problem will not occur.
I want send everyone in server a message or a embed.
I searching google nothing shows up .
I Saw some bots doing anonuncements. PM everyone.
How i can do that . I want a working example i was using discord js .
The most effective way to do this would be to make an announcement channel and get the bot to "#everyone".
If you want to DM everyone in the server, loop through a servers members list and DM each user individually; remember that Discord limits 5 messages per every 5 seconds, so put a delay in your loop.
Discord Api got limits There are limitations with bot DMs, which you can read at https://discordapp.com/developers/docs/topics/rate-limits
Better to mention everyone or role.
This is not recommended, as the Discord API has limits. On the other hand, sending multiple direct messages to users will cause your bot to get blacklisted from "Possible Spam".
Still, you can achieve this as follows:
// Assuming 'guild' is the Server Guild
guild.members.cache.each(member => {
// Send message
member.user.send('An amazing message!').catch(e => {
// An error has occurred
console.log(e);
});
});
It is possible to go loop through and DM all of the users. However, with the Discord API having limitations this can be more tricky with a large server and you are going to want to implement a sleep function.
Use the code:
guild.members.cache.forEach(m => {
m.user.send('Hello this is a dm!')
})
As Morgan said it is probably easier to simply create a channel and just #everyone
Discord prohibits you from mass dming users.
and you will get rate limited
İ'm Getting this error i try use example bot some user but getting this error when type help
AttributeError: 'Message' object has no attribute 'guild'
Please help also getting this error
also so much error getting more on hastebin https://hastebin.com/ipalesajus.sql
Message documentation.
Based on the documentation stated, there is no guild property in Message. I believe what you are looking for is the server property instead.
(Instead of Message.guild, use Message.server)
Note that it might return a None if the message was in a DM, etc.
Based on that, the example bot is probably suited for older versions of Discord.py instead. You might have to make a few edits to the bot to match up with the newest version.
Also, make sure that you downloaded the library/API the example bot used too.