【发布时间】:2021-07-04 04:12:53
【问题描述】:
如果用户滥用它(例如发送垃圾邮件命令和其他东西),我如何让我的机器人从使用中排除某人
@client.command(pass_context = True, aliases = ['bban'])
@commands.is_owner()
async def botban(ctx, member: discord.Member = None, banreason='Kein Grund angegeben!'):
if member is None:
em = discord.Embed(color = 0xff2200, title = "Argumente Fehlen!",
description = f"{ctx.author.mention} Bitte nenne den User, den du vom Bot ausschließen willst\n\n```py\no?botban [@nutzer / id] [(optional) Grund]\n```\n Optional: ```py\no?bban [@nutzer / id] [(optional) Grund]\n```",
footer = f'User-ID: ' + str(ctx.author.id) + ' Made by Ohnezahn DNC#8135 with discord.py')
em.set_author(name = f'{ctx.author.name}#{ctx.author.discriminator}',
icon_url = f'{ctx.message.author.avatar_url}')
return await ctx.send(embed = em)
elif message.author.id in 'blacklist.json': # Check if user already banned
return await ctx.send(
f"Der Nutzer {member.id} / {member.name} - {member.discriminator} ist bereits ausgeschlossen! Grund:\n\n{banreason}")
elif member.id not in 'ban.json':
with open('ban.json', 'w') as fp:
json.dump(banlist, fp)
emb = discord.Embed(color = 0xff2200, title = "Bot Ban ausgeführt",
description = f'{member.mention} / {member.name}#{member.discriminator} / {member.id} wurde von {ctx.author.name}#{ctx.author.discriminator} / {ctx.author.id} / {ctx.author.mention} vom Bot ausgeschlossen\n\nGrund: {banreason}',
footer = f'User-ID: ' + str(member.id) + '/ Made by Ohnezahn DNC#8135 with discord.py')
emb.set_author(name = f'{ctx.author.name}#{ctx.author.discriminator}',
icon_url = f'{ctx.message.author.avatar_url}')
return await ctx.send(embed = emb)
else:
# Add ban to dict
banlist[member.id] = banreason
# Update File
with open('ban.json', 'w') as fp:
json.dump(banlist, fp)
emb = discord.Embed(color = 0xff2200, title = "Bot Ban ausgeführt",
description = f'{member.mention} / {member.name}#{member.discriminator} / {member.id} wurde von {ctx.author.name}#{ctx.author.discriminator} / {ctx.author.id} / {ctx.author.mention} vom Bot ausgeschlossen\n\nGrund: {banreason}',
footer = f'User-ID: ' + str(member.id) + '/ Made by Ohnezahn DNC#8135 with discord.py')
emb.set_author(name = f'{ctx.author.name}#{ctx.author.discriminator}',
icon_url = f'{ctx.message.author.avatar_url}')
return await ctx.send(embed = emb)
@client.check
def check_commands(ctx):
# Check if user banned, convert id to str because json.load (line 9) load str id's.
return str(ctx.author.id) not in blacklisted_users()
这就是我的ban.json现在的样子:
{
"blacklistedUsers": [
]
}
这就是我现在拥有的代码...我现在正在为感觉年龄而努力...
【问题讨论】:
-
这些
assert声明的目的是什么? python中的一切都是一个对象,它永远是True -
欢迎来到堆栈!最简单的方法是创建一个
json,然后无论何时运行此命令,您都可以使用Global Check 来检查用户是否在其中。如果您愿意,可以阅读有关使用 json in the linked docs 的更多信息 -
一个更简单的选择是使用冷却时间
-
@ŁukaszKwieciński 冷却时间!= 机器人排除...它只是让用户等到他/她可以再次使用该命令
标签: discord.py