discord.py AttributeError: 'ClientUser' object has no attribute 'avatar_url'?
Hi, 

ich bau momentan einen discord Bot mit python der ein Formular strten soll.

Code:

@bot.command()
async def testform(ctx):
    form = Form(ctx,'Title')
    form.add_question('Question 1','first')
    form.add_question('Question 2','second')
    form.add_question('Question 3','third')
    await form.start()

Error:

2023-09-09 08:58:09 ERROR    discord.ext.commands.bot Ignoring exception in command testform
Traceback (most recent call last):
  File "/usr/local/python/3.10.4/lib/python3.10/site-packages/discord/ext/commands/core.py", line 235, in wrapped
    ret = await coro(*args, **kwargs)
  File "/workspaces/moon/dir/.py/homeworkBOT/main.py", line 43, in testform
    await form.start()
  File "/usr/local/python/3.10.4/lib/python3.10/site-packages/discord/ext/forms/form.py", line 221, in start
    embed.set_author(name=f"{self.title}: {n+1}/{len(self._questions)}", icon_url=self._bot.user.avatar_url)
AttributeError: 'ClientUser' object has no attribute 'avatar_url'


The above exception was the direct cause of the following exception:


Traceback (most recent call last):
  File "/usr/local/python/3.10.4/lib/python3.10/site-packages/discord/ext/commands/bot.py", line 1350, in invoke
    await ctx.command.invoke(ctx)
  File "/usr/local/python/3.10.4/lib/python3.10/site-packages/discord/ext/commands/core.py", line 1029, in invoke
    await injected(*ctx.args, **ctx.kwargs)  # type: ignore
  File "/usr/local/python/3.10.4/lib/python3.10/site-packages/discord/ext/commands/core.py", line 244, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'ClientUser' object has no attribute 'avatar_url'

Ich verstehe nicht was mit 'avatar_url' gemeint ist da ich diese nicht in meinem Code benutze.

Ich hoffe jemand kann mir helfen.

Code, Python, Forms, Python 3, Discord, Discord Bot
Warum bekomme ich den Wert „none“ von der API zurück?

Ich arbeite gerade an einem Sprachassistenten, der mit

gpt-3.5-turbo 

kommunizieren soll, bekomme aber bei jeder Anfrage nur den Wert

none

zurück. Kann mir jemand sagen warum?

Mein Code:

import speech_recognition as sr
import openai
import pyttsx3

class ChatGPT:
  def __init__(self, api_key, rolle):
    openai.api_key = api_key
    self.dialog = [{"role":"system", "content":rolle}]

  def fragen(self, frage):
    self.dialog.append({"role":"user","content":"frage"})
    ergebnis = openai.ChatCompletion.create(
      model='gpt-3.5-turbo',
      messages=self.dialog
    )
    antwort = ergebnis.choices[0].message.content
    self.dialog.append({"role":"assistant","content":antwort})

def gpt(frage):
  if __name__ == '__main__':
    API_KEY = "sk-..."
    chat_gpt = ChatGPT(API_KEY, "...!")
    antwort = chat_gpt.fragen(frage)
    print(antwort)
    return antwort

def mikrofon_zu_text():
  # Initialisiere das Recognizer-Objekt
  recognizer = sr.Recognizer()
  recognizer.energy_threshold = 4000 

  while True:
    # Öffne das Mikrofon für die Aufnahme
    with sr.Microphone() as source:
      print("wait...")
      audio = recognizer.listen(source, timeout=5) 

      try:
        # Versuche, den Text zu erkennen
        text = recognizer.recognize_google(audio, language='de-DE')

        if "Sprache" in text or "sprache" in text:
          speak("Ich höre")
          print("Aufnahme gestartet.")
          audio = recognizer.listen(source, timeout=5) 
          transcription = recognizer.recognize_google(audio, language='de-DE')
          print("input: " + transcription)
          output = gpt(transcription)
           speak(output)

      except sr.RequestError as e:
        print("Fehler bei der Spracherkennung: {0}".format(e))

      except:
        print("~")

def speak(text):
 
  engine = pyttsx3.init() # object creation
  voices = engine.getProperty('voices')    #getting details of current voice
  engine.setProperty('voice', voices[0].id) #changing index, changes voices. o for male
  engine.say(text)
  engine.runAndWait()
speak("test")

# Aufruf der Funktion
mikrofon_zu_text()

Ich dachte, es könnte mein API-Schlüssel sein, aber ich habe andere Konten als andere verwendet und mein Guthaben beträgt nicht weniger als 5 $. Ich habe auch versucht, die Variable zu verfolgen, aber sie ändert sich nur von

Null

zu

 None
GPT, Programmiersprache, Python, API, Python 3, ChatGPT, OpenAI
Weitere Inhalte können nur Nutzer sehen, die bei uns eingeloggt sind.