Discord bot นไม่ออนไลน์

0

คำถาม

ฉันเพิ่งเริ่มเรียนเป็นภาษาไพธอนและฉัน discord bot จะไม่ไปออนไลน์ มันบอกแค่ว่า "ระบวนการทางออกกับทางออกรหัส 0". และไม่มีข้อผิดพลาดกับรหัส

นี่คือตอบสนองรหัสผม ป้อนรูปภาพรายละเอียดที่นี่

discord discord.py python
2021-11-23 04:23:03
3
0

เพิ่ม await client.process_commands(ctx) แล้ว @client.event ไม่ต้องการวงเล็บรอบจำนวนเงิ(). ใช้รหัสให้ด้านล่างนี้:

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

  await client.process_commands(ctx)

ใช้มันทั้งหมดรหัสถ้ามันยังไม่ได้ทำงาน:

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")
2021-11-23 05:57:23

ขอบคุณแต่ที่ bot ยังไม่ได้เชื่อมต่อ.
Shir0

ฉันต้องแก้ไขของฉันโพสต์เพื่อทั้งหมดรหัสลองออกไป
Siddhant Chauhan

มันยังไม่ได้ผลหรอก ไม่มีข้อผิดพลาดในการหัสและหลังจากที่ผมวิ่งโปรแกรมมันบอกแค่ว่า"กระบวนการเสร็จสิ้นโดยทางออกรหัส 0".
Shir0

นั่นหมายความว่าไม่มีข้อผิดพลาดอยู่ในนรหัสแต่คุณต้องตรวจสอในการตั้งค่าของคุณแบบ ide: stackoverflow.com/a/61883867/16203851
Siddhant Chauhan
0

คุณน่าจะลองนี่แทน

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)
2021-11-23 05:19:54
-1

รหัสที่คุณให้มันผิดนี่คือคำตอบที่ถูกต้อง:

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!

คุณสามารถหาที่สำหรับเอกสารคู่มือ@info:shell discord.py มาที่นี่.

2021-11-23 06:00:41

ขอบคุณแต่ที่ bot ยังไม่ได้เชื่อมต่อ. ไม่พบข้อผิดพลาด
Shir0

คุณควรจะเป็น.ซองแฟ้มนี้บตั๋วเข้าใช้งานหรืออย่างอื่นนี้จะไม่ทำงาน
DevER-M

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................