首页 > 解决方案 > 我在 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')

标签: pythondiscord.py

解决方案


你错过了await一行中的一个括号,你只关闭了两个中的一个:

async def ping(ctx):
  await ctx.send(discord.Embed(title='Latency', description=f'{bot.latency} ms')

推荐阅读