python - 我在 discord.py 中制作了一个 Bot,当我运行项目时,它指向 bot.run('My Token') 并说语法无效
问题描述
我在 discord.py 中制作了一个 Bot,当我运行项目时,它指向 bot.run('My Token') 并说语法无效。我已确保使用机器人而不是客户端设置前缀。请帮忙
这是错误:文件“main.py”,第 25 行 bot.run('My Token') ^ SyntaxError: invalid syntax
这是代码:
import discord
from discord import Member
from discord.ext import commands, tasks
from discord.ext.commands import has_permissions, MissingPermissions, Bot
bot = commands.Bot(command_prefix='-')
@bot.event
async def on_ready():
print('Bot is ready!')
@bot.command(name='ping', aliases=['latency'])
async def ping(ctx):
await ctx.send(discord.Embed(title='Latency', description=f'{bot.latency} ms')
bot.run('My Token')
解决方案
你错过了await
一行中的一个括号,你只关闭了两个中的一个:
async def ping(ctx):
await ctx.send(discord.Embed(title='Latency', description=f'{bot.latency} ms')
推荐阅读
- python - 使用比较函数查找两个对象列表的交集
- html - 我将如何构建这个?(带有头像和过渡的图片卡)
- python-3.x - NetworkX 似乎在 graphml 元素声明中删除了信息——有没有办法恢复它?
- c# - Stephen Cleary 关于异步的新日志记录模式问题
- ios - API_DEPRECATED_WITH_REPLACEMENT 到底是什么意思?
- javascript - 如何通过 Javascript 设置 xlsx 文件的计算模式?
- python - 减去两个列表,但值在 Python 中没有相加
- javascript - 尝试连接 mongoDB 时,打字稿发布未定义
- facebook-graph-api - 无法使用 Graph API v10.0 检索 Facebook 广告报告
- java - Java中文档的页数