python - discord.Client 是否与 discord.py 的 discord.ext.commands 兼容?
问题描述
我有一个非常年轻的机器人,我想添加一个 automod 功能。但是,我的机器人是用 discord.ext.commands 编写的,要扫描所有消息,我需要 discord.Client(我认为)。我不确定它们是否可以同时运行,但它们是否兼容?
解决方案
You don't need discord.Client. If you are already using discord.ext.commands, you can do it as follows.
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_message is called when a Message is created and sent. discord.Intents.messages must be enabled or you use intents = discord.Intents.all() to enable all Intents
推荐阅读
- c++ - 删除对象时调用的测试函数
- lyx - 将图形嵌入 .lyx 文件而不是链接外部文件?
- bluetooth-lowenergy - Bluez BLE 连接监控使用 DBUS-Python
- sql - 存储过程执行触发期间的死锁
- c++ - 计算分布的逆 CDF
- android - Android Studio 既找不到物理设备也找不到 AVD
- npm - 避免'npm install'?
- c# - Unity中的SimpleJSON不解析
- vb.net - 更改面板的可见性(Windows 窗体)
- google-play - App Store 和 Google Play 的 URL 格式,用于安装带有深层链接的应用程序