【发布时间】:2021-01-06 01:17:53
【问题描述】:
在执行 !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”文本框。如何将“No Category”修改为“Commands”或完全删除第一个文本框?
【问题讨论】: