【发布时间】:2021-05-14 07:40:30
【问题描述】:
我在发出命令后尝试“@”特定成员,以下似乎不起作用。
from tokens.token import discord_token
from discord.ext import commands
from discord.utils import get
intents = discord.Intents(messages=True, guilds=True)
client = commands.Bot(command_prefix="!",intents = intents)
@client.event
async def on_ready():
print("Bot is ready!")
@client.command
async def play(ctx):
paul = get(ctx.guild.members, name = 'paul')
john = get(ctx.guild.members, name = 'john')
await ctx.send("f{paul.mention} {john.mention} lets play games!")
client.run(discord_token)
它应该返回类似的东西
MyBotName: @john @paul lets play games!
谢谢!
【问题讨论】:
-
您需要启用 Intent,更多信息请参考:discordpy.readthedocs.io/en/latest/intents.html 同时确保启用特权成员 Intent。
-
@ŁukaszKwieciński 添加意图后,我仍然收到错误
Command raised an exception: AttributeError: 'NoneType' object has no attribute 'mention' -
我看到您实际上启用了一些意图,尽管您缺少
intents.members,正如我在上面的评论中所说,请确保启用它们 -
@ŁukaszKwieciński 有没有办法遍历多个人并提及他们?而不是手动指定 get?
-
“循环多人”是什么意思?您的意思是遍历成员名称/ID 列表?
标签: python python-3.x discord discord.py