python新手,但可以';不要让这个不和谐的机器人运行,我没有错误,我在服务器上有它我做错了什么? 机器人

python新手,但可以';不要让这个不和谐的机器人运行,我没有错误,我在服务器上有它我做错了什么? 机器人,python,discord,discord.py,discord.py-rewrite,Python,Discord,Discord.py,Discord.py Rewrite,我正在pycharm中运行它。我按下run,它就运行了,没有错误,但我不确定它为什么不能在discord上工作。这是一个设置错误吗 import discord import random import time import asyncio TOKEN = "*************************************************" client = discord.Client() @client.event async def on_message(mess

我正在pycharm中运行它。我按下run,它就运行了,没有错误,但我不确定它为什么不能在discord上工作。这是一个设置错误吗

import discord
import random
import time
import asyncio

TOKEN = "*************************************************"

client = discord.Client()

@client.event
async def on_message(message):
    if message.author == client.user:
        return

if message.content.startswith("Hello"):
    await message.channel.send("Hi it is me KEVIN")

@client.event
async def on_ready():
print("running rn sir")

如果您的代码看起来像是在这里共享的,那么这是由于一些小错误造成的

  • 有几行缩进不正确
  • 您需要初始化bot
  • 我更正了代码,所以它应该可以工作

    import discord
    import random
    import time
    import asyncio
    
    TOKEN = "*************************************************"
    
    client = discord.Client()
    
    @client.event
    async def on_message(message):
        if message.author == client.user:
            return
    
        if message.content.startswith("Hello"):
            await message.channel.send("Hi it is me KEVIN")
    
    @client.event
    async def on_ready():
        print("running rn sir")
    
    client.run(TOKEN, bot=True, reconnect=True)
    

    为了帮助可能遇到类似问题的其他人,请解释您是如何解决该问题的