我为我的discord bot向服务器内外的massban成员发出了此命令。结果发现我得到了一个错误:
discord.ext.commands.errors.CommandInvokeError: Command raised an
exception: HTTPException: 400 Bad Request (error code: 50035): Invalid
Form Body In message_id: Value "757201002062544946 759785520065806366"
is not snowflake.
列出的ID是真实的ID,是massban命令的测试对象
这是我的密码
@client.command(aliasas=['mb'])
@commands.has_permissions(ban_members = True)
async def massban(ctx, *, ids:str):
await ctx.channel.fetch_message(ids)
ids = ids.split(" ")
success = 0
for id in ids:
await client.guild.ban(int(id), delete_message_days=0)
success += 1
await ctx.send("Massbanned " + str(success) + " member/s.")
试试这个:
首先,导致错误的是这一行:
await ctx.channel.fetch_message(ids)
,这在您的案例中是不必要的第二,
await client.guild.ban(int(id), delete_message_days=0)
并不是禁止成员的方式。属性client
不接受guild
。相反,它应该是ctx.guild.ban()
最后,当您将
id
变量转换为整数时,它不会直接转换为discord用户。在大多数情况下,您应该使用client.get_user(id)
方法来呈现用户对象因此,在本例中,您将使用如下命令:
[prefix]massban id1 id2 id3 ...
我想在这里回答我自己的问题,因为我知道了。首先,我将字符串列表转换为
int
,因为它会导致错误,然后使用该int list
使用foreach loop
来获取/获取它们的ID并逐个禁止它们。这也适用于公会以外的用户相关问题 更多 >
编程相关推荐