【问题标题】:Command Without Prefix Discord.py Rewrite命令不带前缀 Discord.py 重写
【发布时间】:2021-04-04 15:51:23
【问题描述】:

如何在discord.py rewrite中使用某些不带前缀的命令?

例如,我不想在这个命令中使用前缀,怎么办?

@bot.command(aliases=['2344',
                        '4324',
                        '3673',
                        '1325'])

async def _codes(ctx, amount=2):
    user = ctx.message.author
    role = discord.utils.get(ctx.guild.roles, name='testrole')
    await user.add_roles(role)
    embed = discord.Embed(title='Verification Successful',
                            colour= discord.Colour.green())
    embed.set_thumbnail(url='https://upload.wikimedia.org/wikipedia/commons/thumb/8/8c/White_check_mark_in_dark_green_rounded_square.svg/600px-White_check_mark_in_dark_green_rounded_square.svg.png')
    await ctx.send(embed=embed, delete_after=1 )
    await ctx.channel.purge(limit=amount)```

【问题讨论】:

  • 你想用什么代替前缀?
  • 使用on_message 来做到这一点。检查消息内容是否以您想要的开头。
  • this 回答你的问题了吗?

标签: python discord discord.py discord.py-rewrite


【解决方案1】:

这样做:

list = {'2344','4324','3673','1325'}
@bot.event
async def on_message(message):
    if message.content in list:
        user = message.author
        role = discord.utils.get(ctx.guild.roles, name='testrole')
        await user.add_roles(role)
        embed = discord.Embed(title='Verification Successful', colour = discord.Colour.green())
embed.set_thumbnail(url='https://upload.wikimedia.org/wikipedia/commons/thumb/8/8c/White_check_mark_in_dark_green_rounded_square.svg/600px-White_check_mark_in_dark_green_rounded_square.svg.png')
        await message.channel.send(embed=embed)
        await message.channel.purge(limit=2)

【讨论】:

    【解决方案2】:
    @client.event
    async def on_message(message):
        message.content = message.content.lower()
        if message.content.startwith("command_name"):
            user = message.message.author
            role = discord.utils.get(message.guild.roles, name='testrole')
            await user.add_roles(role)
            embed = discord.Embed(title='Verification Successful',
                                colour= discord.Colour.green())
        await ctx.send(embed=embed, delete_after=1 )
    

    【讨论】:

      猜你喜欢
      • 2021-02-03
      • 2021-02-07
      • 2019-11-09
      • 2021-04-04
      • 2020-10-19
      • 2021-07-15
      • 2021-03-06
      • 2021-07-07
      • 2020-05-03
      相关资源
      最近更新 更多