你怎么说

2024-04-27 00:04:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要提到一个id为631147065925173310的特定角色。我什么都试过了,很多人对我说我不懂python,这很难,但我只学了2天discord.py。你知道吗

if channel.name == "General":
    await ctx.send(f"{ctx.author.mention}needs help at{channel.mention})
else:
    await ctx.send(f"{ctx.author}needs help at an unknown place")

每当有人写“h”的时候,我都要这样或者帮助,它会说:

@user needs help at #channel @specific role

Tags: namepysendid角色ifchannelhelp
2条回答

你可以试试

user = self.bot.get_user(ctx.author.id)
role = ctx.guild.get_role(631147065925173310)
await ctx.send(f"{user.mention} needs help in {ctx.channel.mention}, please attend {role.mention}")

如果您在cog中使用这个,请使用我的代码,如果您使用bot作为命令。你知道吗

如果您在主命令中使用此命令,请使用bot.get_user(ctx.author.id)而不是我的命令。你知道吗

要提到角色或用户,您应该在邮件中使用以下语法:

你知道吗<;@id>;你知道吗

因此,将“id”改为相应角色的id,这样您的代码将是:

awit ctx.send(f"<@{userId}>nedds help at<@{channelId}>)

相关问题 更多 >