如何修复"语法错误:语法无效"在discord bot中

时间:2017-11-26 13:50:43

标签: python syntax-error bots discord

我是编程新手。我一直试图制作一个不和谐的机器人,但每次我尝试启动它都会失败SyntaxError: invalid syntax

代码:

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

Client = discord.Client()
bot_prefix= "^"
client = commands.Bot(command_prefix=bot_prefix)

@client.event
async def on_ready():
    print("Bot Online!")
    print("Name: {}".format(client.user.name))
    print("ID: {}".format(client.user.id))

@client.command(pass_context=True)
async def ping(ctx):
    await client.say("Pong!")

client.run("ID")

错误:

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

1 个答案:

答案 0 :(得分:0)

您必须将机器人令牌放入 client.run('your bots token here') 不是ID

您可以在Google上获取如何获取机器人令牌的信息

还要选中此basic bot example