【问题标题】:Discord.py unable to send message to right userDiscord.py 无法向正确的用户发送消息
【发布时间】:2021-05-04 21:31:54
【问题描述】:

好的,所以我制作了一个 modmail 机器人,以防你们不知道什么是 modmail 机器人 基本上,我服务器中的用户可以将其作为票证发送,我的团队成员会做出回应。 它有一个关闭功能,当我在管理员聊天票中关闭而不是关闭它时,我无法修复它向制作票证的用户发送消息,它最初是给我发消息,但现在改为不发消息一。我需要帮助修复它。

from discord import utils
import discord
import asyncio
class onMessage(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.Cog.listener()
    async def on_message(self, message):
        if message.author.bot:
            return

        if isinstance(message.channel, discord.DMChannel):
            guild = self.bot.get_guild(787409126908755978)
            categ = utils.get(guild.categories, name = "Modmail tickets")
            if not categ:
                overwrites = {
                    guild.default_role : discord.PermissionOverwrite(read_messages = False),
                    guild.me : discord.PermissionOverwrite(read_messages = True),
                    guild.staff : discord.PermissionOverwrite(read_messages = True)
                }
                categ = await guild.create_category(name = "Modmail tickets", overwrites = overwrites)

            channel = utils.get(categ.channels, topic = str(message.author.id))
            if not channel:
                channel = await categ.create_text_channel(name = f"{message.author.name}#{message.author.discriminator}", topic = str(message.author.id))
                await channel.send(f"New modmail created by {message.author.mention}")
                await message.author.send('Hello, Thanks for Messaging VOID Modmail, Please State your Issue Or Question And Our Staff Will Be With You As Soon As Possible.')
                message.author.mention = self.member

            embed = discord.Embed(description = message.content, colour = 0x696969)
            embed.set_author(name = message.author, icon_url = message.author.avatar_url)
            await channel.send(embed = embed)

        elif isinstance(message.channel, discord.TextChannel):
            if message.content.startswith(self.bot.command_prefix):
                pass
            else:
                topic = message.channel.topic
                if topic:
                    member = message.guild.get_member(int(topic))
                    if member:
                        embed = discord.Embed(description = message.content, colour = 0x696969)
                        embed.set_author(name = ('VOID Staff'), icon_url = message.author.avatar_url)
                        await member.send(embed = embed)
        self.member = message.author.id

    @commands.command("close")
    async def close(self, ctx):
        if ctx.channel.category.name == "Modmail tickets":
            await ctx.send("Deleting the channel in 5 seconds!")
            await asyncio.sleep(5)
            await ctx.channel.delete()
            await self.member.send('This Ticket Has been closed, Feel Free To DM If More Help Is Needed')


def setup(bot):
    bot.add_cog(onMessage(bot))```

【问题讨论】:

    标签: python discord discord.py bots


    【解决方案1】:

    这是因为您尝试向self.member 发送未定义的消息,在这种情况下,您需要重新检查频道主题,因为您使用它来存储用户的 id。

    我建议使用数据库,而不是将内容存储在频道主题中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-08
      • 2013-06-11
      • 2019-06-02
      • 1970-01-01
      • 2020-02-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多