基本上,我希望我的机器人执行的操作是使用给定的最小用户命令创建帖子,使用react对自己的帖子做出反应,一旦满足the的最小反应量,它就会发布一条新消息,标记该人做出了命令,其他做出反应的人。
我已经通过谷歌搜索等尝试了许多事情,由于很多内容都是不可重写的,因此很难理解。我对python并不熟悉,所以只是看一下文档并没有多大帮助,而且我知道我是否了解到很多我可能会理解的python基础知识,但我只想做一个机器人。 / p>
<code>#imports
import discord
import sys
from discord.ext import commands
bot = commands.Bot(command_prefix = '.')
annChan = 3333#fake chan num
TOKEN = 3333#fake token
people = []
minPeople = 1
chan = None
@bot.event
async def on_ready():
global chan
chan = bot.get_channel(annChan)
print('Bot is ready.')
@bot.command()
async def test(ctx, arg1, arg2, arg3):
people.append(ctx.message.author.id)
global minPeople
minPeople = arg2
msg = await chan.send('<@{}> is looking to go to '.format(ctx.message.author.id)
+ arg1
+ ' and is hoping for '
+ arg2
+ ' other person(s) to come.\nWhen: '
+ arg3
+'\nReact with :thumbsup: if you\'re interested! @everyone')
await msg.add_reaction('?')
bot.run('TOKEN')
到目前为止,我只让机器人发布了具有所需参数的消息,然后用ing对其自身消息做出反应。
我不知道如何检查?是否达到'arg2'提供的数量,然后满足要求后,标记消息的创建者和所有对该消息做出反应的人都用?告知他们达到最低要求。
我已经看到人们说使用“ reactions.count”,但是我不知道该怎么做,也不知道该如何抓住每个做出反应的人以后再对其进行标记。
感谢任何愿意花时间帮助我理解和使之正常工作的人。
答案 0 :(得分:0)
这是一个命令,它会在每次反应后检查到目前为止是否有正确的人数响应。您还应该给参数提供真实名称,而不是arg1
,arg2
。很难说出这些参数应该是哪种值:
thumbs_up = "\N{THUMBS UP SIGN}"
def check_count_reaction(emoji, desired_count, message):
def predicate(reaction, user):
return reaction.message == message and reaction.emoji == emoji and reaction.count>=desired_count
return predicate
@bot.command()
async def test(ctx, destination, number: int, condition):
msg = await ctx.send(f"{ctx.author.mention} is looking to go to {destination} and "
"is looking for {number} other people to come.\n"
"When:\n {condition}\nReact with {thumbs_up} if you're interested! "
await msg.add_reaction(thumbs_up)
"{ctx.guild.default_role.mention}")
reaction, user = await bot.wait_for('reaction_add', check=check_count_reaction(thumbs_up, number+1, msg))
users = await reaction.users().flatten()
users = [u for u in users if not u.bot]
await ctx.send(f"{ctx.author.mention}, {', '.join(m.mention for m in users)} are coming with you!")