Answer the question
In order to leave comments, you need to log in
Why can't I use the kick function?
There are 5 discord servers. 4 primary servers and 1 secondary. In the secondary, it was necessary to check the corresponding roles to other 4 servers, and if the participant does not have this role in the corresponding server, then he must be kicked from the secondary. I made the code using a crutch and I can't get the kick function to work, because it gives an error. Help, please, to understand. So far, there are 1 primary and 1 secondary server in the code.
The code:
import discord
import asyncio
from discord.ext import commands
token = 'TOKEN'
GUILD_1=653925478545096715
GUILD_HP=653925807776858201
client=commands.Bot(command_prefix='#')
@client.event
async def on_ready():
print('BOT connected')
#ЧП
check_list(GUILD_HP, "1")
check_list(GUILD_1, "1") #Список людей из 1
#HYDRA
hydra(GUILD_1,"1")
def check_list(GUILD, ID):
for guild in client.guilds:
if guild.id == GUILD:
break
f = open(str(GUILD)+'_id_'+ID+'.txt', 'w')
for member in guild.members:
for role in member.roles:
if role.name == ID:
f.write(str(member.id)+'\n')
f.close()
@client.command(kick_members=True)
async def hydra(GUILD,ID):
for guild in client.guilds:
if guild.id == GUILD:
break
kick=[] #Которые будут кикнуты
per_HP=[] #Список всех людей в HP
per=[] #Люди в 1
with open(str(GUILD)+'_id_'+ID+'.txt', "r") as file:
per = file.read().splitlines()
with open(str(GUILD_HP)+'_id_'+ID+'.txt', "r") as file:
per_HP = file.read().splitlines()
for k in range(len(per)):
per[k]=int(per[k])
for k in range(len(per_HP)):
per_HP[k]=int(per_HP[k])
for k in range(len(per_HP)):
if per_HP[k] not in per:
kick.append(per_HP[k])
print('Кол-во:',len(kick),'\nБудут кикнуты:',kick,'\n\n')
for guild in client.guilds:
if guild.id == 653925807776858201:
break
for k in range(len(kick)):
mem=guild.get_member(kick[k])
await client.kick(mem,reason=None)
client.run(token)
Warning (from warnings module):
File "C:\Users\USER\Desktop\HP\HP.py", line 29
hydra(GUILD_1,"1")
RuntimeWarning: coroutine 'Command.__call__' was never awaited
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question