Discord.py生成仅用于服务器的命令

2024-09-29 23:30:36 发布

您现在位置:Python中文网/ 问答频道 /正文

因此,我尝试创建一个签入命令,该命令仅在特定服务器中工作,这取决于频道的组织方式。有没有办法检查命令运行的位置,如果不是来自这个特定的公会/服务器,就阻止它

我的命令我试图锁定一个特定的公会

@commands.command()
#something here to check guild?
async def checkin(self, ctx):
    category = discord.utils.get(ctx.guild.categories, id=catID)
    checkinem = discord.Embed(title='Realms Channels')
    
    for channel in category.channels: # or text_channels or voice_channels
        realm, emoji = channel.name.split('-')
        checkinem.add_field(name=realm, value=emoji, inline=False)
        
    checkinmsg = await ctx.send(embed=checkinem)
    for channel in category.channels: 
      realm, emoji = channel.name.split('-')
      await checkinmsg.add_reaction(emoji=emoji)

任何帮助都将不胜感激,再次感谢


Tags: namein命令服务器forchannelctxchannels
2条回答

您可以在命令开始时进行检查

@commands.command()
async def checkin(self, ctx):
    if ctx.guild.id is not 1234564789: #This is the wanted guild id
        return
    #code here
@commands.command()
@commands.guild_only()

如果你想要一个特定的公会,你也可以按照阿卜杜勒·阿齐兹的建议去做

相关问题 更多 >

    热门问题