gpt4 book ai didi

discord - discord bot 1.7.3 错误给出很长的错误

转载 作者:行者123 更新时间:2023-12-02 05:47:06 27 4
gpt4 key购买 nike

我试图制作一个 discord 聊天机器人,但我收到了这个错误我不确定我使用 discord 1.7.3 的方式该怎么做这里是 DISCORD KEY 和 OPENAI-KEY 不是的代码这些问题是隐藏我的 openai key 和 discord 机器人 key :

import discord
import asyncio
import openai
import os

openai.api_key = os.environ.get('OPENAI-KEY')

client = discord.Client()

@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
if message.author == client.user:
return

if message.content.startswith('$hello'):
await message.channel.send('Hello!')
elif message.content.startswith('$chat'):
response = openai.Completion.create(
engine="davinci",
prompt=message.content[5:],
max_tokens=100,
temperature=0.9,
top_p=1,
n=1,
stream=False,
logprobs=None,
stop=["\n"],
)
await message.channel.send(response['choices'][0]['text'])

client.run(os.environ.get('DISCORD-TOKEN'))

这是我遇到的错误:

import discord
import asyncio
import openai
import os

openai.api_key = os.environ.get('OPENAI-KEY')

client = discord.Client()

@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
if message.author == client.user:
return

if message.content.startswith('$hello'):
await message.channel.send('Hello!')
elif message.content.startswith('$chat'):
response = openai.Completion.create(
engine="davinci",
prompt=message.content[5:],
max_tokens=100,
temperature=0.9,
top_p=1,
n=1,
stream=False,
logprobs=None,
stop=["\n"],
)
await message.channel.send(response['choices'][0]['text'])

client.run(os.environ.get('DISCORD-TOKEN'))

这是我得到的错误

Traceback (most recent call last):
File "c:\Users\Private\OneDrive\Desktop\Pro\GitHub Repo\Discord_chat_bot\Bot.py", line 35, in <module>
client.run(os.environ.get('DISCORD-TOKEN'))
File "C:\Users\Private\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\client.py", line 723, in run
return future.result()
File "C:\Users\Private\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\client.py", line 702, in runner
await self.start(*args, **kwargs)
File "C:\Users\Private\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\client.py", line 665, in start
await self.login(*args, bot=bot)
File "C:\Users\Private\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\client.py", line 511, in login
await self.http.static_login(token.strip(), bot=bot)
AttributeError: 'NoneType' object has no attribute 'strip'

如果我在 2.0.0 discord 中尝试这段代码,我希望它能工作,它会给出不同的错误

我使用 1.7.3 而不是 2.0.0 的原因是因为我有一个不同的错误,为了修复它我不得不切换到 1.7.3

最佳答案

此行错误:

client.run(os.environ.get('DISCORD-TOKEN'))

您传入的 token 是 None,因为 os.environ.get('DISCORD-TOKEN') 返回 None。

您可能忘记了设置环境变量,或者您将它放在 .env 文件中。如果您在 .env 文件中有它,请加载它:

from dotenv import load_dotenv

load_dotenv()

关于discord - discord bot 1.7.3 错误给出很长的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74592733/

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