亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Discord.Client 是否與discord.py 的discord.ext.commands

Discord.Client 是否與discord.py 的discord.ext.commands

四季花海 2023-10-26 10:48:53
我有一個非常幼稚的機器人,我想添加一個自動調節功能。但是,我的機器人是用discord.ext.commands編寫的,要掃描所有消息,我需要discord.Client(我認為)。我不確定它們是否可以同時運行,但它們兼容嗎?
查看完整描述

1 回答

?
猛跑小豬

TA貢獻1858條經驗 獲得超8個贊

你不需要不和諧的客戶端。如果您已經在使用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_message 在消息創建和發送時被調用。必須啟用discord.Intents.messages,或者使用intents = discord.Intents.all()來啟用所有Intents


查看完整回答
反對 回復 2023-10-26
  • 1 回答
  • 0 關注
  • 125 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號