【问题标题】:Python discord bot closes/crashes immediately after openingPython不和谐机器人在打开后立即关闭/崩溃
【发布时间】:2020-12-18 08:00:03
【问题描述】:

我正在尝试使用 discord.py 为我的不和谐服务器制作一个不和谐机器人,我有非常基本的代码应该让机器人在线但只是打开然后崩溃。

import discord

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

client.run('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')

我确实有令牌,我只是不想泄露。感谢所有帮助。

【问题讨论】:

  • 以一种允许您获取它崩溃的错误的方式运行。在控制台中运行它以使其保持打开状态,或者在 IDE 或其他东西中运行。

标签: python discord bots


【解决方案1】:

我找到了一个不错的 tutorial 来在 python 中创建一个不和谐的机器人。因此,您可以使用以下代码创建连接:

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”或其他名称,这样与导入没有冲突。

【讨论】:

    猜你喜欢
    • 2018-07-12
    • 2021-08-03
    • 2020-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-17
    相关资源
    最近更新 更多