#python #discord #discord.py
#python #Discord #discord.py
Вопрос:
Итак, в настоящее время я пытаюсь создать музыкального бота discord и кодирую его в 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)```
Комментарии:
1. Не могли бы вы показать нам ошибки?
Ответ №1:
Эти круглые скобки рядом с вашими декораторами могут быть виновниками, попробуйте избавиться от них. Кроме того, не стоит размещать свой токен там, где его могут видеть другие люди 😉
Комментарии:
1. Пожалуйста, напишите полное решение вопроса. Спасибо
Ответ №2:
попробуйте использовать ctx вместо контекста
#commands and stuff
@client.command()
async def play(ctx, url : str ):