制作discord bot时出现Python语法错误

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (318)

当我尝试编写一个简单的机器人,在调用“!cookie”时发送一个cookie表情符号,我收到此错误消息。

RESTART: C:/Users/matth/AppData/Local/Programs/Python/Python37-32/InfoBot.py 
Traceback (most recent call last):
   File "C:/Users/matth/AppData/Local/Programs/Python/Python37-32/InfoBot.py", line 1, in <module>
import discord
  File "C:\Users\matth\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\__init__.py", line 20, in <module>
from .client import Client, AppInfo, ChannelPermissions
  File "C:\Users\matth\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\client.py", line 38, in <module>
from .state import ConnectionState
  File "C:\Users\matth\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\state.py", line 36, in <module>
from . import utils, compat
  File "C:\Users\matth\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord\compat.py", line 32
create_task = asyncio.async
                          ^
SyntaxError: invalid syntax

这是我的代码。

import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio
import time

Client = discord.Client()
client = commands.Bot(command_prefix = "!")

@client.event
async def on_ready():
    print("Bot is ready!")

@client.event
async def on_message(message):
    if message.content == "cookie":
        await client.send_message(message.channel, ":cookie:")




client.run("********************************")

我正在审查我的令牌,但我希望这不会干扰解决问题。谢谢<3

提问于

扫码关注云+社区

领取腾讯云代金券