【问题标题】:Discord py - if emoji in new created channel - delete the channelDiscord py - 如果新创建的频道中有表情符号 - 删除频道
【发布时间】:2020-10-27 16:47:33
【问题描述】:

大家好!

我正在尝试为我的服务器制作一个小票机器人 - 问题是反应中的表情符号删除了一个频道!

因此,如果成员在新创建的频道之外使用表情符号,它将删除该频道:(

我的代码现在是什么样子的:

@commands.Cog.listener()
async def on_raw_reaction_add(self, payload):
    guild_id = payload.guild_id
    guild = self.client.get_guild(guild_id)
    user_id = payload.user_id
    user = self.client.get_user(payload.user_id)
    message_id = payload.message_id
    emoji = payload.emoji.name

    if message_id == 768765161301213185 and emoji == "????":
        member = discord.utils.find(lambda m : m.id == payload.user_id, guild.members)
        support_role = guild.get_role(760792953718308915)
        category = guild.get_channel(768764177736400906)
        overwrites = {
            guild.default_role: discord.PermissionOverwrite(read_messages=False),
            member: discord.PermissionOverwrite(read_messages=True, send_messages=True),
            support_role: discord.PermissionOverwrite(read_messages=True, send_messages=True)
        }

        ticket_nr = random.randint(100,999)
        channel = await category.create_text_channel(f'ticket-{ticket_nr}', overwrites=overwrites)

        embed = discord.Embed(
            title="How can I help you?",
            description="Please wait for a supporter.")
        embed.set_author(name="TiLiKas Ticket Bot")

        for channel_all in guild.text_channels:
            if str(channel_all) == str(channel):
                if user_id != 739740219544305714 and emoji == "????":
                    await channel.delete(reason=None)
                else:
                    print("ERROR")

我想要什么?

如果它在新创建的频道中使用,我希望机器人只响应表情符号!

【问题讨论】:

    标签: python discord discord.py discord.py-rewrite


    【解决方案1】:

    https://discordpy.readthedocs.io/en/latest/ext/commands/api.html?highlight=check#discord.ext.commands.Bot.wait_for

    @client.event
    async def on_message(message):
        if message.content.startswith('$thumb'):
            channel = message.channel
            await channel.send('Send me that ? reaction, mate')
    
            def check(reaction, user):
                return user == message.author and str(reaction.emoji) == '?'
    
            try:
                reaction, user = await client.wait_for('reaction_add', timeout=60.0, check=check)
            except asyncio.TimeoutError:
                await channel.send('?')
            else:
                await channel.send('?')
    

    您的 check 方法应该类似于:

    def check(reaction, user):
        return user == message.author and str(reaction.emoji) == '?' and reaction.message.channel == message.channel
    

    这里检查,检查:

    • 对消息做出反应的用户与启动命令的用户相同。
    • 反应是竖起大拇指的表情符号。
    • 反应在启动命令的同一通道中完成。

    【讨论】:

    • 这对我不起作用 - 机器人的反应应该被忽略 - 我必须如何更改 def 命令?
    • 机器人的反应被忽略。它正在检查“对消息做出反应的用户与启动命令的用户相同。”你应该展示你的新代码。
    • 问题是我调用了一个命令,这个命令发送了一条消息,我只是点击了反应。我在命令中添加了反应 - 我也会在我的新代码中显示这个:)
    • 我应该编辑我的第一篇文章还是应该使用回答您的问题
    猜你喜欢
    • 2021-02-06
    • 1970-01-01
    • 1970-01-01
    • 2021-09-21
    • 1970-01-01
    • 2020-12-06
    • 1970-01-01
    • 2021-02-04
    • 2020-04-18
    相关资源
    最近更新 更多