我与许多合作伙伴的服务器一起工作,共享禁止突袭的禁令。通常,我会得到一个user_id列表和一个禁令原因。然后使用dyno bot禁止他们,因为dyno bot可以禁止不在您服务器中的成员。但是,现在我将禁止日志数据库添加到我的机器人中,我希望能够禁止不在服务器中的成员。
@client.command()
@commands.has_permissions(ban_members=True)
async def ban(ctx, member : discord.Member, *, reason=None):
new_color = stuff
hex_color = stuff
if reason == None:
embed = discord.Embed(title=f"Woah {ctx.author.name}, Make sure you provide a reason!", color=int(hex_color, 16))
await ctx.send(embed=embed)
else:
dmban=(f"You have been banned from {ctx.guild.name} for '{reason}'.")
embed=discord.Embed(title=f"{member.name} has been banned from {ctx.guild.name} for {reason}", color=int(hex_color, 16))
embed.add_field(name=f":newspaper: {reason}", value=f"User id: {member.id}", inline=True)
embed.add_field(name="User joined:", value=member.joined_at, inline=True)
inlul = client.get_channel(channel_id)
now = datetime.now()
formatted_date = now.strftime('%Y-%m-%d %H:%M:%S')
db = sqlite3.connect('main.sqlite')
cursor = db.cursor()
sql = ("INSERT INTO banlog(mod_name, mod_id, reason, datetime, ban_name, ban_id) VALUES(?,?,?,?,?,?)")
val = (ctx.author.name, ctx.author.id, reason, formatted_date, member.name, member.id)
cursor.execute(sql, val)
db.commit()
cursor.close()
db.close()
await member.send(dmban)
await guild.ban(discord.Object(id=member_id), reason=reason)
await inlul.send(embed=embed)
我尝试使用await guild.ban(discord.Object(id=member_id)
,我在github页面上找到了有关使用它通过user_id禁止的信息。但是对我来说,它不会禁止用户,但是会将禁止添加到数据库中。我不确定是否要为member_id创建一个变量。
答案 0 :(得分:1)
尝试这样做:
更改命令以将用户ID用作args,然后使用它来查找和禁止用户。
user = await bot.fetch_user(int(args))
await ctx.guild.ban(user)