Answer the question
In order to leave comments, you need to log in
I want my discord bot to leave the servers that are on the list. It gives an error, how to fix it?
I tried to make such code. But it gives an error, it does not depend on the list, I have already checked. Here is the code:
@bot.event
async def on_connect(guild):
black = [#потом поставлю айди серверов]
if guild.id in black:
await bot.leave_guild()
Answer the question
In order to leave comments, you need to log in
The function bot.leave_guild
does not exist in the current version of the library. Much of the functionality in the rewrite version of the library has been moved to the appropriate models .
The event on_connect
is fired when connected to Discord , not when the bot is added to the server.
When a bot is added to the server, an event is called on_guild_join
: https://discordpy.readthedocs.io/en/stable/api.htm...
Thus:
GUILD_BLACKLIST = [779450659245255793, 853811295717358421, ...] # Список ID
@bot.event
async def on_guild_join(guild):
if guild.id in GUILD_BLACKLIST:
print(f"Guild {guild.name} ({guild.id}) is blacklisted! Leaving…"
await guild.leave()
@bot.event
async def on_connect(guild):
black = ["""потом поставлю айди серверов"""]
if guild.id in black:
await bot.leave_guild()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question