我为我的不和谐机器人向在服务器内外的 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 命令的测试对象。</p>
这是我的代码
@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.")
答案 0 :(得分:0)
试试这个:
@client.command(aliasas=['mb'])
@commands.has_permissions(ban_members = True)
async def massban(ctx, *, ids:str):
list_of_ids = ids.split(' ')
success = 0
for id in list_of_ids:
id = client.get_user(int(id))
await ctx.guild.ban(id, reason='You were mass-banned')
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
变量转换为整数时,它不会直接转换为不和谐用户。在大多数情况下,您应该使用 client.get_user(id)
方法来呈现用户对象。
因此在这种情况下,您将使用如下命令:[prefix]massban id1 id2 id3 ...
答案 1 :(得分:0)
我会在这里回答我自己的问题,因为我想通了。首先,我将字符串列表转换为 int
,因为它会导致错误,然后使用 int list
使用 foreach loop
获取/获取它们的 id 并一一禁止它们。这也适用于公会以外的用户。
@client.command(aliasas=['mb'])
@commands.has_permissions(administrator = True)
async def massban(ctx, *, ids:str):
list_of_ids = ids.split(' ')
list_of_idsx = list(map(int, list_of_ids))
success = 0
for id in list_of_idsx:
user = await client.fetch_user(id)
await ctx.guild.ban(user, delete_message_days=0)
success += 1
await ctx.send("Massbanned " + str(success) + " member/s.")