2 回答
TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超11個(gè)贊
Member.roles是一個(gè)Role對象列表,而不是字符串。您可以使用discord.utils.getid(作為 int)來搜索該列表。
from discord.utils import get
@client.command(aliases=['Ban'])
async def ban(ctx, member: discord.Member, days: int = 1):
if get(ctx.author.roles, id=548841535223889923):
await member.ban(delete_message_days=days)
await ctx.send("Banned {}".format(ctx.author))
else:
await ctx.send("{}, you don't have permission to use this command.".format(ctx.author))
await ctx.send(ctx.author.roles)
也不再有Client.ban協(xié)程,附加參數(shù)Member.ban必須作為關(guān)鍵字參數(shù)傳遞。
TA貢獻(xiàn)1887條經(jīng)驗(yàn) 獲得超5個(gè)贊
async def ban(ctx, member: discord.Member=None, *, reason=None):
if reason:
await member.send(f'You got banned from {ctx.guild.name} by {ctx.author}, reason: ```{reason}```')
await member.ban()
await ctx.send(f'{member.mention} got banned by {ctx.author.mention} with reason: ```{reason}```')
if reason is None:
await ctx.send("please specify a reason")
添加回答
舉報(bào)
