python的新手,但是无法运行此discord机器人,我没有错误,并且在服务器上有错误,我在做什么错?

时间:2020-06-18 04:16:22

标签: python discord discord.py discord.py-rewrite

bot.py

我正在pycharm中运行它。我按下run键,它运行并没有错误,但是我不确定为什么它在不一致时不起作用,这是设置错误吗?

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")

1 个答案:

答案 0 :(得分:1)

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

  1. 一些行没有正确缩进。
  2. 您需要client.run来初始化漫游器

我已更正代码,因此它应该可以工作

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)