简体   繁体   English

我怎样才能让我的 discord 机器人在键入时提到特定的人?

[英]How can I make it so my discord bot mentions a specific person when they type?

So I'm putting this in a Cog.所以我把它放在一个 Cog 中。 I want to make it so that if the author is a specific person and they type anything, the bot will mention them and reply.我想这样做,如果作者是一个特定的人并且他们输入任何内容,机器人会提及他们并回复。

import discord
from discord.ext import commands

client = discord.Client()

class jtieu(commands.Cog):

    def __init__(self, client):
        self.client = client


    @commands.Cog.listener()
    async def on_ready(self):
        print("Bot 3 is ready.")

    @commands.Cog.listener()
    async def jtieu2(self, ctx):
        if ctx.author == "CxS#3441" :
            await ctx.channel.send(f"{ctx.author.mention} ok")



def setup(client):
    client.add_cog(jtieu(client))

I'm not too sure if I'm supposed to use ctx.author.mention in this context, and I'm fairly new to how Cogs work in discord.py.我不太确定我是否应该在这种情况下使用 ctx.author.mention,而且我对 Cogs 在 discord.py 中的工作方式还很陌生。

If you are creating a mention specifically for one user it might be a better idea to copy the user's id and use it instead of a nickname as it will work even when they change their name.如果您要专门为某个用户创建提及,则复制用户的 id 并使用它而不是昵称可能是一个更好的主意,因为即使他们更改了他们的名字,它也会起作用。

@commands.Cog.listener()
async def on_message(self, message):
    if message.author.id == 1234567890: # example id
        await message.channel.send(f"{message.author.mention} ok")

Remember that it requires intents.messages .请记住,它需要intents.messages

Simple Cogs Example 简单的齿轮示例

暂无
暂无

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

相关问题 如何让我的 Discord 机器人提及频道中的特定人员? - How can i make my Discord bot mention a specific person in the channel? 如何让我的 discord.py 机器人提及我的消息中提到的某人? - How can I make my discord.py bot mentions someone mentioned in my message? 当我使用函数获取前缀时,如何让我的 Discord 机器人同时响应自定义前缀和提及? - How to make my Discord bot respond to both custom prefixes and mentions when I use a function to get the prefix? 如何让我的 Discord.py 机器人计算一个人的消息? - How do I make, so my Discord.py bot counts a person's messages? 如何做到这一点,以便我的 discord 机器人只接受启动命令的人的输入 - How do I make it so my discord bot only take inputs from the person that started the command 我将如何做到这一点,以便个人是唯一可以使用 discord 机器人运行命令的人? - How would I make it so that an individual person is the only one who can run a command with a discord bot? 让 Discord 机器人 DM 成为特定的人 - Make a Discord bot DM a specific person 当语音频道中的人说话时,我可以让 discord python 机器人识别吗? - Can I make a discord python bot recognize when a person in a voice channel talks? 当我的机器人或其他机器人在命令中使用时,如何让我的机器人说些什么? (不和谐.py) - How can I make my bot say something when it or another bot is used in the command? (discord.py) 当特定用户在频道中发送消息时,如何让我的 discord 机器人响应? - How do I make my discord bot respond when a specific user sends a message in the channel?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM