亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

禁止命令 discord.py 的問題(重寫分支)

禁止命令 discord.py 的問題(重寫分支)

慕村225694 2022-01-05 20:21:57
我一直在用 discord.py(重寫分支)編寫一個機器人程序,我想添加一個禁止命令。機器人仍然沒有禁止該成員,它只是顯示一個錯誤:@client.command(aliases=['Ban'])async def ban(ctx,member: discord.Member, days: int = 1):    if "548841535223889923" in (ctx.author.roles):        await client.ban(member, 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)      它會禁止被 ping 的用戶并確認它確實禁止了
查看完整描述

2 回答

?
Qyouu

TA貢獻1786條經驗 獲得超11個贊

Member.roles是一個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協程,附加參數Member.ban必須作為關鍵字參數傳遞。


查看完整回答
反對 回復 2022-01-05
?
慕工程0101907

TA貢獻1887條經驗 獲得超5個贊

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")


查看完整回答
反對 回復 2022-01-05
  • 2 回答
  • 0 關注
  • 220 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號