【发布时间】:2020-12-03 14:36:28
【问题描述】:
我与许多合作服务器合作,共同分享反袭击禁令。通常我会得到一个 user_ids 列表和禁止原因。然后使用 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 创建了一个 var。
【问题讨论】:
标签: python-3.x discord discord.py