Python discord bot在打开后立即关闭/崩溃

2024-09-28 05:21:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用discord.py创建一个discord bot。对于我的discord服务器,我有非常基本的代码,可以让bot联机,但只是打开然后崩溃

import discord

@client.event
asnyc def on_ready():
    print 'bot read`enter code here`y'

client.run('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')

我确实有代币,通常我只是不想泄露。我感谢所有的帮助


Tags: 代码pyimport服务器clienteventreadon
1条回答
网友
1楼 · 发布于 2024-09-28 05:21:22

我找到了一个很好的tutorial来在python中创建一个discord bot。因此,您可以使用以下代码创建连接:

import os

import discord
from dotenv import load_dotenv

load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')

client = discord.Client()

@client.event
async def on_ready():
    print(f'{client.user} has connected to Discord!')

client.run(TOKEN)

我建议将文件从“discord”重命名为“bot”或其他名称,这样就不会与导入冲突

相关问题 更多 >

    热门问题