我需要实现一些功能,其中一个功能是实现投票类型功能。由于一些政策的原因,我们不能使用公共不和谐机器人,所以我们必须自己实施一些东西。昨天做了一些研究,能够使用discord.ext
中的python3和commands
API制作基本的机器人。现在我需要弄清楚的是:
ctx
我可以得到user
tags
(admin等)。有没有更好的办法?在Commands reference page上找不到任何有用的内容,或者我可能正在查看错误的文档。如有任何帮助,我们将不胜感激。
谢谢
更新:谢谢大家。现在我被如何添加表情卡住了,这是我的代码
poll_emojis = {0: ':zero:', 1: ':one:', 2: ':two:', 3: ':three:', 4: ':four:'}
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$create_poll'):
poll_content = message.content.split('"')
poll_text = poll_content[1]
poll_options = []
poll_option_text = ''
count = 0
for poll_option in poll_content[2:]:
if poll_option.strip() != '':
poll_options.append(poll_option)
poll_option_text += '{0}: {1} '.format(poll_emojis[count], poll_option)
count += 1
posted_message = await message.channel.send('**{0}**
{1}'.format(poll_text, poll_option_text))
count = 0
for poll_option in poll_options:
await posted_message.add_reaction(Emoji(poll_emojis[count]))
count += 1
顺便说一句,考虑到您正在开始此项目,并且已经在使用重写文档,请确保您使用的是重写版本。这里有一些关于如何确保以及如何在不确定的情况下获得它的问题,但它记录得更好,更容易使用。我下面的回答假定您正在使用discord.py-rewrite
Message.reactions
是Reaction
的列表。您可以使用
{react.emoji: react.count for react in message.reactions}
您可以在发布消息后立即对其作出反应:
@bot.command()
async def poll(ctx, *, text):
message = await ctx.send(text)
for emoji in ('
声明:本媒体部分图片、文章来源于网络,版权归原作者所有,如有侵权,请联系QQ:330946442删除。