python-3.x - 不和谐机器人的语法无效(python)
问题描述
在左下角,它说我正在使用 Python 3.6 64 位 我正在尝试创建一个不和谐的机器人并从示例中复制并粘贴了此代码,但由于某种原因它似乎不起作用。任何帮助将不胜感激
#Python 3.6
import discord
from discord.ext import commands
from discord.ext.commands import Bot
import asyncio
bot = commands.Bot(commands_prefix='#')
client = discord.Client()
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('!hello'):
msg = 'Hello {0.author.mention}'.format(message)
await client.send_message(message.channel, msg)
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
client.run('token')
我得到的错误是:
[Running] python -u "/Users/brady/Documents/tempCodeRunnerFile.py"
File "/Users/brady/Documents/tempCodeRunnerFile.py", line 12
async def on_message(message):
^
SyntaxError: invalid syntax
[Done] exited with code=1 in 0.092 seconds
我正在尝试在 Visual Studio Code 中运行此代码
解决方案
你用过
bot = commands.Bot(commands_prefix='#')
所以要让它工作,你需要使用
@bot.command()
否则它将无法正常工作。
还有
Client = discord.Client()
这里的部分没用
推荐阅读
- python - 不同大小的列与 kivy
- javascript - 如何从javascript中的其他数组向数组中的对象内的键添加值
- windows - Oracle 从 Windows Mobile SDK(Pocket PC) 获取数据
- html - 如何使用 flexbox 将两个 div 并排放置,使第二个 div 居中?
- python - Telnet客户端控制面板python
- thrift - 无法从 ubuntu 安装 thrift
- django - 502 Bad Gateway django nginx + gunicorn
- c# - 用于继承/类型区分的自定义模型绑定器
- calendar - 使用 .ics 文件自动确认日历中的事件
- r - 修改 R 传单标记的大小