commands von discord lassen sich nicht installieren:

Probleme bei der Installation?
Antworten
crailsoo
User
Beiträge: 1
Registriert: Dienstag 17. Mai 2022, 19:23

Code: Alles auswählen

import asyncio
import discord
from discord.ext import commands
from discord import Member

client = discord.Client(intents=discord.Intents.all(), command_prefix='!')

@client.command()
async def ping(ctx):
    await ctx.send("Pong!")
Jedoch ist ,,from discord.ext import commands" bei mir in Python grau und beim ausführen bekomme ich folgenden error:

Traceback (most recent call last):
File ... , line 56, in <module>
@client.command()
AttributeError: 'Client' object has no attribute 'command'

also bei mir ist in line 56 ,,@client.command()
async def ping(ctx):
await ctx.send("Pong!")" drin.

kann mir jemand weiterhelfen? Ich brauch dies dringend.
Benutzeravatar
sparrow
User
Beiträge: 4164
Registriert: Freitag 17. April 2009, 10:28

Die Import-Zeile ist grau, weil deine IDE merkt, dass du das, was dort importiert wird, nicht verwendest.

Und ansonsten sagt dir die Fehlermeldung ja, was nicht funktioniert. Etwas von dem Typ "Client" hat keine Methode namens "command". Da musst du wohl noch einmal in die Dokumentatin schauen, wie das korrekt geht.
Benutzeravatar
Balmung
User
Beiträge: 44
Registriert: Sonntag 17. März 2013, 18:36

discord.Client hat diese .command Funktionalität nicht. Du musst dir stattdessen eine Instanz von commands.Bot erzeugen:

Code: Alles auswählen

bot = commands.Bot(intents=discord.Intents.all(), command_prefix='!')

@bot.command()
async def ping(ctx):
    ...
Antworten