Discord.py Bot 不响应命令

时间:2021-01-04 04:16:16

标签: python discord discord.py

所以我目前正在尝试创建一个不和谐的音乐机器人并在 vsc 中对其进行编码;但是,当我尝试运行命令时,尽管我认为代码或多或少是正确的,但它们都不起作用。我想知道是否有人可以帮助我。请和谢谢。

import discord
from discord.ext import commands

TOKEN ='' 
#client(the bot)
client = commands.Bot(command_prefix='>')

#commands and stuff
@client.command()
async def play(context, url : str ):
   voiceChannel = discord.utils.get(ctx.guild.voice_channels, name='General') #voiceChannel=ctx.message.author.voice.channel 
   voice = discord.utils.get(client.voice_clients, guild=ctx.guild)
   if not voice.is_connected():
       await voiceChannel.connect()

@client.command()
async def leave(ctx):
    voice = discord.utils.get(client.voice_clients, guild=ctx.guild)
    if voice.is_connected():
        await voice.disconnect()
    else:
        await ctx.send("uwuowo is currently not connected to a voice channel")

@client.command()
async def pause(context):
    voice = discord.utils.get(client.voice_clients, guild=ctx.guild)
    if voice.is_playing():
        voice.pause
    else:
        await ctx.send("no songs are currently playing")

@client.command()
async def resume(ctx):
    voice = discord.utils.get(client.voice_clients, guild=ctx.guild)
    if voice.is_paused():
        voice.resume
    else:
        await ctx.send("audio is currently playing")

@client.command()
async def stop(ctx):
     voice = discord.utils.get(client.voice_clients, guild=ctx.guild)
     voice.stop

#run the client on the server               
client.run(TOKEN)```

2 个答案:

答案 0 :(得分:0)

装饰器旁边的那些括号可能是罪魁祸首,尝试去掉它们。此外,将您的令牌发布在其他人可以看到的地方也不是一个好主意;)

答案 1 :(得分:0)

尝试使用 ctx 而不是上下文

#commands and stuff
@client.command()
async def play(ctx, url : str ):