如何在Discord机器人的帮助命令中修改或删除“无类别”

时间:2020-09-19 08:50:47

标签: python discord bots

这是我得到的结果 enter image description here

执行!help

后从此代码
import discord
from discord.ext import commands
from discord.utils import get
import os
import youtube_dl

token = os.environ.get('DISCORD_TOKEN')
client = commands.Bot(command_prefix='!')


@client.event
async def on_message(message):
    await client.process_commands(message)
    channels = ['bot-commands']
    if str(message.channel) in channels:
        if message.content == '!help':
            embed = discord.Embed(title='How to use the ImposterBot', description='Useful Commands')
            embed.add_field(name='!help', value='Display all the commands')
            embed.add_field(name='!music', value='Play a music playlist')
            embed.add_field(name='!valorant', value='Get the most recent version of Valorant stats')
            embed.add_field(name='!hello', value='Greet a user')
            embed.add_field(name='!join', value='Connect the bot to a voice channel')
            embed.add_field(name='!leave', value='Disconnect the bot')
            await message.channel.send(content=None, embed=embed)
        elif message.content == '!hello':
            await message.channel.send(f'Greeting, {message.author}!')
        elif message.content == '!valorant':
            await message.channel.send('This feature is not ready yet')
        elif message.content == '!music':
            await message.channel.send('This feature is not ready yet')


@client.command(pass_context=True)
async def join(ctx):
    """ join the voice channel """
    channel = ctx.message.author.voice.channel
    voice = get(client.voice_clients, guild=ctx.guild)

    if voice and voice.is_connected():  # if already on a channel
        await voice.move_to(channel)  # move to the user's channel
    else:
        voice = await channel.connect()
    await ctx.send(f'Joined {channel}')  # if not joined yet, connect to the voice channel


@client.command(pass_context=True)
async def leave(ctx):
    """ leave the voice channel """
    channel = ctx.message.author.voice.channel
    voice = get(client.voice_clients, guild=ctx.guild)

    if voice and voice.is_connected():
        await ctx.send(f'Disconnecting from channel **{channel}**')  # if already connected
        await voice.disconnect()  # disconnect
    else:
        await ctx.send("I'm not connected in any channel")  # if not connected, send this message

client.run(token)

在添加!join和!leave命令之前,它仅显示“如何使用ImposterBot”文本框。如何将“无类别”修改为“命令”或完全删除第一个文本框?

1 个答案:

答案 0 :(得分:0)

关注this guide

它将帮助您制作更好更详细的帮助命令,因此您不必自己编写每一个命令。还要避免对命令使用 on_message 事件