不和谐机器人不会上线



我刚开始学习python,我的discord机器人不会上线。它只是说"进程退出,退出代码为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")

您应该试试这个

import os
import discord
from discord.ext import commands

discord_token = "Your Token"

client = discord.Client()

bot = commands.Bot(command_prefix="s!")
@bot.event
async def on_ready():
print("running")
bot.run(discord_token)
@bot.command()
async def on_ready():
print("running")
bot.run(discord_token)

且输出应运行

你应该试试这个

import os
import discord
from discord.ext import commands
discord_token = "Your Token"
client = discord.Client()
bot = commands.Bot(client_prefix="!")
@client.command()
async def on_ready():
print("running")
bot.run(discord_token)

您给出的代码是错误的,这是正确的:

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的文档。

相关内容

  • 没有找到相关文章

最新更新