gpt4 book ai didi

运行代码时,Python Discord 机器人无法上线

转载 作者:太空宇宙 更新时间:2023-11-03 20:03:33 28 4
gpt4 key购买 nike

我正在使用 PyCharm 制作一个不和谐的机器人,并且正在遵循教程 ( https://www.youtube.com/watch?v=nW8c7vT6Hl4 )。我遵循了每一步,最后一切都正确,但每当我运行视频末尾的代码时,机器人都不会如图所示上线。

import discord
from discord.ext import commands

client = commands.Bot(command_prefix= '.')

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

client.run('token')

显然,“ token ”是我从 Discord 网站获得的 token ,但我仍然遇到问题。

我也没有收到任何错误,代码运行得很好。

这是 PyCharm 的“运行”窗口中显示的唯一内容。

C:\Users\user\PycharmProjects\discord\venv\Scripts\python.exe

最佳答案

从您的代码来看,您似乎没有导入 asyncio

Asyncio 处理异步函数,并且是 Discord.py 库运行的要求。要导入它,请输入 import asyncio。希望这能解决您的问题!

关于运行代码时,Python Discord 机器人无法上线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59096206/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com