【发布时间】:2021-06-09 01:21:27
【问题描述】:
所以我一直在为不和谐创建一个机器人,所以我一直在关注许多教程,但我唯一的命令不会运行。所以这是我的代码:
import discord
import os
from discord.ext import commands
client = discord.Client()
bot = commands.Bot(command_prefix = "_")
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith("salut le bot"):
await message.channel.send("Salut, je suis Bapo Bot, pour vous servir !")
if message.content.startswith("merci fréro"):
await message.channel.send("De rien mon gars !")
if str(message.channel) == "uniquement-des-images" and message.content != "":
await message.channel.purge(limit=1)
print('Message :', (message.content), 'from', (message.author), 'deleted successfully.')
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print(discord.__version__)
print('------------------')
@bot.command()
async def ping(ctx):
await ctx.send('Pong!')
client.run(os.environ['BOT_TOKEN'])
此代码没有给出任何错误。
起初我认为client = discord.Client() 正在创建错误,但是当我删除它时,整个机器人不再工作了。我尝试更改 bot 前缀或更改现在称为 bot 的东西的名称(我仍然是 python 中的菜鸟,所以我不知道这个东西叫什么),现在我被卡住了。
编辑:由于答案已被版主(?)删除,这是解决方案。不能将on_message 函数与命令函数同时使用。
【问题讨论】:
标签: python discord.py