[英]how do i make this command only work in multiple channels using discord.py
我正在嘗試使命令在 2 個貿易渠道中發揮作用,因為它是為了檢查人們的擔保以查看他們是否值得信賴。 我當前的代碼不起作用,但在這里
@client.command()
async def vouches(ctx, member : discord.User=None):
if None == member:
await open_vouches(ctx.author)
user = ctx.author
users = await get_vouch_data()
vouches_given = users[str(user.id)]["vouches_given"]
vouches_gotten = users[str(user.id)]["vouches_gotten"]
embed = discord.Embed(title='Trade vouches!',color=0x1d9521)
embed.add_field(name='Vouches Gotten✨',value=vouches_gotten, inline=False)
embed.add_field(name="Vouches Given🏦", value=vouches_given, inline=False)
await ctx.reply(embed=embed)
elif ctx.channel.id != 813832766248583199:
await ctx.send("You can't vouch in this channel")
return
elif ctx.channel.id != 813832801220689931:
await ctx.send("You can't vouch in this channel")
return
else:
await open_vouches(member)
users = await get_vouch_data()
vouches_given = users[str(member.id)]["vouches_given"]
vouches_gotten = users[str(member.id)]["vouches_gotten"]
embed = discord.Embed(title=f'{member}\'s Trade vouches!',color=0x1d9521)
embed.add_field(name='Vouches Gotten✨',value=vouches_gotten, inline=False)
embed.add_field(name="Vouches Given🏦", value=vouches_given, inline=False)
await ctx.reply(embed=embed)
print('[LOGS] bot was used for Vouches')
但 elif: 部分是我想要使用的。 我之前問過一個與此類似的問題,但只使用一個渠道,所以請幫助我。 提前謝謝你,是的,我試過把身份證放在一起,諸如此類
首先 - 你必須先檢查頻道。 在您提到的評論中,您在測試時沒有將成員作為參數傳遞,這意味着代碼的那部分永遠不會到達,因為member
總是None
所以它進入第一個if
。
@client.command()
async def vouches(ctx, member : discord.User=None):
allowed_channels = [813832766248583199, 813832801220689931]
# Check channels FIRST
if ctx.channel.id not in allowed_channels:
return await ctx.send("You can't vouch in this channel")
此外,應該使用is
完成None-checks
,而不是==
。
elif member is None:
...
PS。 這沒有錯,但是如果上面的if-statements
使用return
s,則不需要使用elif
。 如果輸入了上述if/elif
之一,則 function return
s,因此無論如何都無法到達elif
下方。
最后, member is None
並且members is not None
使用不同的userid
完全相同,考慮只創建一個具有id
的變量或創建一個 function 而不是復制該代碼塊。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.