不和谐的机器人不会在网上去

0

的问题

我刚开始学习python和我的不和谐的机器人不会在网上去。 它只是说 "过程中退出,退出代码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

谢谢,但是机器人仍然离线。
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!

你可以找到的文件discord.py 在这里.

2021-11-23 06:00:41

谢谢,但是机器人仍然离线。 没有发现错误
Shir0

你应该有一个。env文件,这令牌,否则这不会工作
DevER-M

其他语言

此页面有其他语言版本

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