【问题标题】:discord.py Cog // how to send message to specific channediscord.py Cog // 如何将消息发送到特定通道
【发布时间】:2021-05-18 23:33:43
【问题描述】:
@commands.Cog.listener()
async def on_message(self, message):
    channel = self.client.get_channel(797863482380124170)
    if message.channel.id in talk_channel:
        stats = levelling.find_one({"id": message.author.id})
        if not message.author.bot:
            if stats is None:
                newuser = {"id": message.author.id, "xp": 100}
                levelling.insert_one(newuser)
            else:
                xp = stats["xp"] + 100
                levelling.update_one({"id": message.author.id}, {"$set": {"xp": xp}})
                lvl = 0
                while True:
                    if xp < ((50 ** (lvl ** 2)) + (50 * lvl)):
                        break
                    lvl += 1
                    # lvl += 1
                xp -= ((50 * ((lvl - 1) ** 2)) + (50 * (lvl - 1)))
                
                if xp == 0:
                    await message.channel.send(f"{message.author.mention} Lvl Up!")

所以这是我的代码,但 await message.channel.send 不起作用请帮助我

我尝试了很多方法,但都不起作用

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    await channel.send() 应该没问题。你可以在这里阅读更多:discordpy.readthedocs.io

    【讨论】:

    • 我认为通道不起作用,因为 OP 已经定义了channel = self.client.get_channel(797863482380124170),它不一定与发生消息事件的通道相同。
    猜你喜欢
    • 2022-01-22
    • 2021-02-19
    • 1970-01-01
    • 2019-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-18
    相关资源
    最近更新 更多