我刚开始学习python和我的不和谐的机器人不会在网上去。 它只是说 "过程中退出,退出代码0". 而且也没有错误代码。
这是我的代码。 该图像描述这里
我刚开始学习python和我的不和谐的机器人不会在网上去。 它只是说 "过程中退出,退出代码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(cloient_prefix="!")
@client.command()
async def on_ready():
print("running")
other codes here...
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 在这里.