[英]Discord.py ban all members
我正在嘗試制作禁止服務器中所有成員的代碼。 這是出於教育原因,不打算在真實服務器中進行。 我目前的代碼是:
@client.command()
async def d(ctx):
for member in list(ctx.guild.members):
try:
await member.ban(reason="pooooop", delete_message_days=7)
print(f"Banned {member.display_name}!")
print("Banning is complete!")
except Exception:
pass
該代碼沒有任何錯誤,但對命令沒有反應。
@client.command()
async def massban(ctx):
for user in ctx.guild.members:
try:
await user.ban()
except:
pass
你可以遍歷所有成員並禁止他們
你的代碼無論如何都應該工作
文檔禁令
我已經這樣做了,但不是禁止,我只是打印名稱只是為了測試它但它只打印一個名稱
@bot.command(pass_context = True)
async def ban(ctx):
guild = ctx.message.guild
for member in ctx.guild.members:
print(member)
對於 guild.ban 中的成員:嘗試: await member.ban(ctx.guild.members)
這很容易我為此做了一些
有要求:
@client.command()
async def banall(ctx):
for member in list(ctx.guild.members):
id = ctx.guild.id
userid = member.id
r = requests.put('https://discord.com/guilds/{id}/bans/{userid}', headers={ 'Authorization': 'put bot token here' })
if r.status_code != 200:
await ctx.send(f'Banned {userid}')
elif r.status_code != 429:
await ctx.send(f'Could not ban {userid}\nReason: Status Code 429 Rate limited')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.