【问题标题】:How would I make my bot say something when a channel is created under a category?当在类别下创建频道时,我如何让我的机器人说些什么?
【发布时间】:2020-12-01 04:28:39
【问题描述】:

我正在尝试让我的 Discord 机器人说些什么,并在创建频道等时等待消息,但我不知道该怎么做,这是我现在正在处理的代码:

import discord, asyncio

discord_token = open('token.txt').read()
client = discord.Client()

@client.event
async def on_message(message):
    if message.author == client.user:
        return

    if message.content.lower().startswith('test'):
        await message.channel.send('testing, sending to channel works!')

@client.event
async def on_ready():
    print('Successfully connected to', client.user)

client.run(discord_token)

【问题讨论】:

    标签: discord.py


    【解决方案1】:

    这可以使用 on_guild_channel_create

    来完成
    @client.event
    async def on_guild_channel_create(channel):
        if channel.category: #if the channel created is in a category
            #send something
            await channel.send("Something")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-14
      • 2021-08-02
      • 2021-07-18
      • 2020-12-28
      • 2020-11-05
      • 2021-10-12
      • 2021-11-28
      • 1970-01-01
      相关资源
      最近更新 更多