我想学习如何制作一个discord机器人,但它说的示例代码运行不起来,可能是什么问题?

问题描述 投票:0回答:1

我正在学习如何使用discord.py API和这个示例代码(来自这里。https:/discordpy.readthedocs.ioenlatestquickstart.html)。)不工作。我认为这与async语法有关,但我不知道它可能有什么问题.任何帮助将被感激!

import discord

client = discord.Client()


@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))


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

    if message.content.startswith('$hello'):
        await message.channel.send('Hello!')


client.run('private token that is filled in in the actual code')

在第7行,"async def on_ready():",错误是async语法无效。我使用的是3.8.3版本

python discord discord.py
1个回答
-1
投票

client = commands.Bot(command_prefix = '!') 而不是 client = commands.Client()你应该导入 commands

import discord
from discord.ext import commands
© www.soinside.com 2019 - 2024. All rights reserved.