简体   繁体   中英

Command Without Prefix Discord.py Rewrite

How to use any certain commands without prefix in discord.py rewrite?

for example, i don't want to use the prefix in this command, what to do?

@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)```

Do this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM