【问题标题】:discord.ext.commands.errors.CommandNotFound: Command "play" is not found errordiscord.ext.commands.errors.CommandNotFound:找不到命令“播放”错误
【发布时间】:2021-09-12 00:45:56
【问题描述】:

我正在尝试为不和谐创建一个音乐机器人,我完成了代码并尝试运行它,当我运行播放命令时它只是这么说。

Ignoring exception in command None:
discord.ext.commands.errors.CommandNotFound: Command "play" is not found

这是我的代码。

import discord
from discord.ext import commands
import youtube_dl

TOKEN = "Token here"
bot = discord.ext.commands.Bot(command_prefix = "s ");

@bot.event
    async def on_ready():
    channel = discord.utils.get(bot.get_all_channels(), id=794444804607574026)
    await channel.connect()

 async def play(ctx, url):
     player = await voice_client.create_ytdl_player(url)
     player.start()

 bot.run(TOKEN) 

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    你没有在播放功能上方添加@bot.command(name="play")

    import discord
    from discord.ext import commands
    import youtube_dl
    
    TOKEN = "Token here"
    bot = discord.ext.commands.Bot(command_prefix = "s ");
    
    @bot.event
    async def on_ready():
        channel = discord.utils.get(bot.get_all_channels(), id=794444804607574026)
        await channel.connect()
     
     @bot.command(name="play")
     async def play(ctx, url):
         player = await voice_client.create_ytdl_player(url)
         player.start()
    
     bot.run(TOKEN) 
    

    【讨论】:

      【解决方案2】:

      之前

      async def play(ctx, url):
          player = await voice_client.create_ytdl_player(url)
          player.start()
      

      之后

      @bot.command()
      async def play(ctx, url):
          player = await voice_client.create_ytdl_player(url)
          player.start()
      

      【讨论】:

      • 先加入VC
      • im 在 vc 中,就在我运行播放命令时,似乎什么也没发生。控制台中也没有任何内容。 @Delta
      • 当我运行播放命令@Delta 时似乎什么都没有发生
      【解决方案3】:

      只需使用此代码:

      ma​​in.py

      from discord.ext import commands
      from discord.ext.commands import bot
      
      import discord
      import os
      import youtube_dl
      
      bot = commands.Bot(command_prefix="s")
      
      @bot.event
      async def on_ready()
          print("{0.user} is online".format(bot))
      
      @bot.command()
      async def play(ctx, url):
          player = await voice_client.create_ytdl_player(url)
          player.start()
      

      .env

      TOKEN=<paste your token here>
      

      希望对你有所帮助(:

      【讨论】:

        猜你喜欢
        • 2023-02-25
        • 2021-02-19
        • 1970-01-01
        • 2021-02-06
        • 2014-12-28
        • 2022-01-11
        • 2014-06-11
        • 1970-01-01
        • 2016-03-24
        相关资源
        最近更新 更多