【问题标题】:My python based discord bot is not responding to any commands entered, and the initial method is not printing anything我的基于 python 的不和谐机器人没有响应输入的任何命令,并且初始方法没有打印任何内容
【发布时间】:2021-07-07 22:00:24
【问题描述】:

当我启动我的不和谐机器人时,on_ready 方法不起作用。该机器人上线,但该方法中的任何代码都不会在命令行中打印。此外,info 命令无法正常工作。这是以前与我编写的另一个机器人一起工作的所有代码,所以我不确定什么是失败的。代码如下。

from discord.ext import commands
import discord


client = discord.Client()


TOKEN = "insert token here"
description = "Bot that does things"
bot = commands.Bot(command_prefix="$", description="testbot")


@bot.event
async def on_ready():
    print("Logged in as")
    print(bot.user.name)
    print(bot.user.id)
    print("-----------------")
    print("Developed by")
    print("me")


@bot.command()
async def info(ctx):
    embed = discord.Embed(
        title="Commands", description="Here are the commands:", color=0xFFFF00
    )
    embed.add_field(name="meme", value="gives you a  meme", inline=True)
    print("Cmd entered")


client.run(TOKEN)

【问题讨论】:

    标签: python discord discord.py bots


    【解决方案1】:

    这可能是因为您同时定义了clientdiscord.Client 实例)和botdiscord.ext.commands.Bot 实例)。如果您删除 client 并将 client.run() 更改为 bot.run(),机器人应该可以工作。

    from discord.ext import commands
    import discord
    
    
    TOKEN = "insert token here"
    description = "Bot that does things"
    bot = commands.Bot(command_prefix="$", description="testbot")
    
    
    @bot.event
    async def on_ready():
        ...
    
    @bot.command()
    async def info(ctx):
        ...
    
    
    bot.run(TOKEN)
    

    【讨论】:

    • 是的,命令至少需要缺少的消息意图。
    • @ChrisDewa 我认为消息意图默认设置为True,除非我弄错了
    • 是的,默认情况下所有功能都已启用但具有特权。感谢您的信息
    猜你喜欢
    • 2021-08-18
    • 2021-11-21
    • 2022-06-12
    • 2019-04-13
    • 2022-10-24
    • 1970-01-01
    • 2022-12-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多