当我输入命令时,我的 Discord 机器人不发送消息

问题描述 投票:0回答:1
import discord  #Importation des paquets et des modules nécessaires au bon fonctionnement du bot
from discord.ext import commands

intents = discord.Intents(messages=True, guilds=True)#intents enabling

class MyClient(discord.Client): #Connection message
    async def on_ready(self):
        print(f'Logged on as {self.user}!')

bot = commands.Bot(command_prefix='$', intents=intents) #Setting command prefix

@bot.event #command function definition
async def on_message(message):
    if message.content.startswith('$hello'):
        await message.channel.send('Hello!')







client = MyClient(intents=intents) #starts the bot
client.run('TOKEN')

我是法国人,很抱歉我的英语不好

我目前正在开发一个不和谐的机器人,但是当我调用命令时,它没有响应。 我测试了一个只有通用频道的空服务器 我已经检查过不和谐开发者门户,消息意图已启用。 并且没有错误信息 我在 Ubuntu 23.04 上,在我的 venv 中安装了 python 3.8.0,仅包含 discord.py 包

我尝试了 bot.process_command 但它不适用于多个参数,我搜索了所有网络但没有任何效果,有人可以帮助我吗

python discord discord.py bots
1个回答
0
投票

您可以删除

client
,因为
bot
可以做
client
可以做的所有事情,但更容易。您还可以使用
bot.command()
装饰器轻松定义命令。如果您还有
bot.process_command()
,则只需使用
on_message()

import discord
from discord.ext import commands

intents = discord.Intents.default()
intents.message_content = True

bot = commands.Bot(command_prefix="$",intents=intents)

@bot.command("hello")
async def hello(ctx):
   await ctx.send("Hello!")

bot.run("TOKEN")
© www.soinside.com 2019 - 2024. All rights reserved.