我创建了一个名为 p!poll [message]
的命令,我希望我的机器人发送带有 [message] 的嵌入内容作为描述,并用表情符号 ? 和 ? 做出反应。但是,该命令没有响应,我不明白为什么。
@client.command
async def poll(ctx, *, message):
embedVar = discord.Embed(title='Poll', description=f'{message}')
msg = await ctx.channel.send(embed=embedVar)
await msg.add_reaction('?')
await msg.add_reaction('?')
答案 0 :(得分:1)
你的命令忘记调用命令了,就是双括号,()
只需在顶部添加:client.command()
即可修复,之前没有括号的位置
最好在您的消息装饰器中包含“无”,因为它允许成员知道他们必须通过消息,否则不会运行命令。
我选择为您的命令添加更多功能(仅当您希望使用时)以及将其发送到不同频道的选项,但我已经尝试过并且应该可以工作。希望这会有所帮助,将其更改为您需要的任何内容。
@client.command()
async def poll(ctx, *, message=None):
if message == None:
await ctx.send(f'Cannot create a poll with no message!')
return
questions = [
f"Which channel should your poll be sent to?"
]
answers = []
def check(m):
return m.author == ctx.author and m.channel == ctx.channel
for i in questions:
await ctx.send(i)
try:
msg = await client.wait_for('message', timeout=30.0, check=check)
except asyncio.TimeoutError:
await ctx.send("Setup timed out, please be quicker next time!")
return
else:
answers.append(msg.content)
try:
c_id = int(answers[0][2:-1])
except:
await ctx.send(
f"You didn't mention a channel properly, please format like {ctx.channel.mention} next time."
)
return
channel = client.get_channel(c_id)
embed = discord.Embed(title="Poll", description='{message}', colour=discord.Color.black())
message = await channel.send(embed=embed )
await message.add_reaction('?')
await message.add_reaction('?')