简体   繁体   English

discord.py Cog //如何向特定通道发送消息

[英]discord.py Cog // how to send message to specific channe

@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!")

So this is my code but await message.channel.send doesnt work plz help me所以这是我的代码,但等待 message.channel.send不起作用请帮助我

i tried lots of Way but it doesnt work我尝试了很多方法,但它不起作用

await channel.send() should be fine. await channel.send()应该没问题。 You can read more here: discordpy.readthedocs.io你可以在这里阅读更多内容: discordpy.readthedocs.io

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM