discord.Client是否与discord.ext.commands for discord.py兼容?

2024-06-28 11:08:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个非常幼稚的机器人,我想添加一个automod功能。但是,我的bot是用discord.ext.commands编写的,要扫描所有消息,我需要discord.Client(我想)。我不确定它们是否可以同时运行,但它们是否兼容


Tags: 功能client消息bot机器人extcommandsdiscord
1条回答
网友
1楼 · 发布于 2024-06-28 11:08:24

你不需要不和,客户。如果您已经在使用discord.ext.commands,则可以按如下操作

import discord
from discord.ext import commands


intents = discord.Intents.all()

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


@bot.event
async def on_ready():
    print(f"Bot is ready")
    await bot.change_presence(status=discord.Status.online, activity=discord.Game(name="example"))

@bot.event
async def on_message(message):
    forbidden_word = "word"
    if forbidden_word in message.content:
        await message.delete()

@bot.command()
@commands.has_permissions(kick_members=True)
async def kick(ctx, member: discord.Member):
    await member.kick()
    await ctx.send(f"Member {member} has been kicked")


bot.run("token")

在创建和发送消息时调用on_消息。 必须启用discord.Intents.messages,或者使用Intents=discord.Intents.all()启用所有意图

相关问题 更多 >