【问题标题】:Discord Bot framework crashes on startup (Python)Discord Bot 框架在启动时崩溃(Python)
【发布时间】:2021-02-16 21:40:41
【问题描述】:

一直在尝试遵循有关不和谐机器人的教程,而我所看到的起始框架的每个地方都如下所示:

from imports import *

#link to manage bot

#establishes client for bot
client = commands.Bot(command_prefix = '.')

#create first event, readies the bot for use

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

#run bot from token, DO NOT SHARE TOKEN
client.run(token)
    

但是当我运行它时,它会立即崩溃。令牌是正确的,我确实 pip install discord.py,并且import discord
from discord.ext import commands 都在其中。该机器人都在我的 Discord 上的服务器中,它只是不会出现在网上。请帮忙!

【问题讨论】:

  • crashes 是什么意思?您是否收到任何错误或立即存在的应用程序?
  • @KiraLT 只要我执行就会打开,然后立即退出。如果有的话,我不知道它抛出了什么错误。我尝试做input(),但它仍然崩溃

标签: python discord bots


【解决方案1】:

所以我能够在尝试运行程序时进行屏幕记录,显然有一个ClientConnectorCertificateError,所以我找到了下载证书的地方:https://crt.sh/?id=2835394(在左栏下方下载)然后add it in chrome

【讨论】:

    【解决方案2】:

    如果您遇到任何崩溃或错误,请按照这些步骤进行报告。

    • 如果您还没有安装 C++ 构建工具,因为 discord.py 需要这些工具。
    • 在命令提示符下运行py -3 -m pip install -U discord.py(注意这是针对windows的,如果您使用不同的操作系统,那么您可以检查正确的安装命令here
    • 在命令提示符下导入 discord 只是为了检查它是否安装正确。
    • 确保您已将机器人邀请到您的服务器。

    完成这两个步骤后,运行我编写的这段代码,不要混淆您的客户端密码和您的机器人令牌(我已经看到很多情况发生了)。

    import discord
    from discord.ext import commands
    
    client = commands.Bot(command_prefix='.')
    token = "ENTER-TOKEN-HERE"
    
    @client.event
    async def on_ready():
        print("Bot ready to go")
    
    
    client.run(token)
    

    【讨论】:

    • 所以我再次安装了 pip 以确保它正常工作,但是当我在 cmd 中导入不和谐时,我得到一个 modulenotfounderror?即使在代码编辑器中导入它时,我也可以执行。我仔细检查了我的令牌是否用于机器人,并确保它在服务器中。我运行了你得到的代码并且遇到了同样的问题,它只是在运行时关闭。
    • 我想我缺少 c++ 构建工具,当我查找它以安装它时,它全部用于 Visual Studio。由于我只使用VScode,有没有办法在没有VS的情况下安装它?
    猜你喜欢
    • 1970-01-01
    • 2019-03-12
    • 1970-01-01
    • 2021-04-07
    • 2020-09-01
    • 1970-01-01
    • 2020-08-13
    • 1970-01-01
    • 2018-05-23
    相关资源
    最近更新 更多