第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

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

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

慕村225694 2022-01-05 20:21:57
我一直在用 discord.py(重寫分支)編寫一個(gè)機(jī)器人程序,我想添加一個(gè)禁止命令。機(jī)器人仍然沒有禁止該成員,它只是顯示一個(gè)錯(cuò)誤:@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)      它會(huì)禁止被 ping 的用戶并確認(rèn)它確實(shí)禁止了
查看完整描述

2 回答

?
Qyouu

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ù)傳遞。


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

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


查看完整回答
反對 回復(fù) 2022-01-05
  • 2 回答
  • 0 關(guān)注
  • 240 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)