Právě jsem se začal učit python a můj svár bot nebude jít on-line. to jen řekl "Proces ukončit s návratový kód 0". A tam je žádná chybová s kódem.
tady je můj kód. zadejte popis obrázku zde
Právě jsem se začal učit python a můj svár bot nebude jít on-line. to jen řekl "Proces ukončit s návratový kód 0". A tam je žádná chybová s kódem.
tady je můj kód. zadejte popis obrázku zde
Přidat await client.process_commands(ctx)
a @client.event
nepotřebujeme závorky()
. Použijte kód níže:
@client.event
async def on_message(ctx):
if ctx.author == client.user:
return
await client.process_commands(ctx)
Použít celý tento kód, pokud to stále nefunguje:
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix="!")
@bot.event
async def on_ready():
print('We are logged in!')
@bot.event
async def on_message(message):
if message.author==bot.user:
return
await bot.process_commands(message)
@bot.command()
async def ping(message) :
await message.channel.send("Pong!!")
bot.run("TOKEN")
Měli byste se pokusit to místo
import os
import discord
from discord.ext import commands
discord_token = "Your Token"
client = discord.Client()
bot = commands.Bot(cloient_prefix="!")
@client.command()
async def on_ready():
print("running")
other codes here...
bot.run(discord_token)
Kód, který jste dal je špatné, toto je správné:
import os
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix="!") # you don't need an extra discord.client Bot is enough
token = os.getenv("TOKEN")
#you should not run the program here you should run it at last
@bot.event #no need for brackets
async def on_ready():
print("running")
@bot.event
async def on_message(ctx):
if ctx.author == client.user:
return
@bot.command(name="span",description="YOUR DESCRIPTION HERE") # it is command and not commands
async def span_(ctx,amount:int,*,message):
for i in range(amount):
await ctx.send(message)
bot.run(token) #you should run the bot now only and this will work perfectly!
Můžete najít dokumentaci pro discord.py tady.