首页 > 解决方案 > 当在类别下创建频道时,我如何让我的机器人说些什么?

问题描述

我正在尝试让我的 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

解决方案


这可以使用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")

推荐阅读