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