Python反应中的Discord Bot
我希望,当有人对一个表情符号做出反应时,机器人会将其写为登录聊天,如下所示: @圣诞老人有新闻4️⃣ 我试着去,但我被卡住了Python反应中的Discord Bot,python,discord,bots,discord.py,Python,Discord,Bots,Discord.py,我希望,当有人对一个表情符号做出反应时,机器人会将其写为登录聊天,如下所示: @圣诞老人有新闻4️⃣ 我试着去,但我被卡住了 import discord import time import random from discord.ext import commands client = discord.Client() bot = client.user if message.content.startswith('ººrandgame'): original = await
import discord
import time
import random
from discord.ext import commands
client = discord.Client()
bot = client.user
if message.content.startswith('ººrandgame'):
original = await message.channel.send('Discover the number I my mind...')
uno = await original.add_reaction('1️⃣')
dos = await original.add_reaction('2️⃣')
tres = await original.add_reaction('3️⃣')
cuatro = await original.add_reaction('4️⃣')
cinco = await original.add_reaction('5️⃣')
seis = await original.add_reaction('6️⃣')
siete = await original.add_reaction('7️⃣')
ocho = await original.add_reaction('8️⃣')
nueve = await original.add_reaction('9️⃣')
diez = await original.add_reaction('You can use a reaction_wait_for
, this will always wait for the author of the message input of the specified reaction.
Below I've made a simple user reaction command but I'll leave it up to you how you would further like to improve it.
message = await ctx.send("React to a number")
one = '1️⃣'
two = '2️⃣'
await message.add_reaction(one)
await message.add_reaction(two)
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in [one, two]
member = ctx.author
while True:
try:
reaction, user = await client.wait_for("reaction_add", timeout=600.0, check=check)
if str(reaction.emoji) == one:
await ctx.send("You choose 1")
if str(reaction.emoji) == two:
await ctx.send("You choose 2")
导入不一致
导入时间
随机输入
从discord.ext导入命令
client=discord.client()
bot=client.user
如果message.content.startswith('randgame'):
original=wait message.channel.send('Discover the number I my mind…'))
uno=等待原件。添加反应('1️⃣')
dos=等待原件。添加反应('2️⃣')
tres=等待原件。添加反应('3️⃣')
cuatro=等待原件。添加反应('4️⃣')
cinco=等待原始。添加反应('5️⃣')
seis=等待原件。添加反应('6️⃣')
siete=等待原件。添加反应('7️⃣')
ocho=等待原始。添加反应('8️⃣')
nueve=等待原件。添加反应('9️⃣')
diez=wait original.add_reaction(“您可以使用reaction_wait_for
,这将始终等待指定反应的消息输入作者
下面我做了一个简单的用户反应命令,但我将把它留给您如何进一步改进它
@client.command()
async def ººrandgame(ctx):
.... Rest of your code ...
在您的代码中,我还建议使用asyncio.sleep(15)
而不是time.sleep
,因为这会导致整个bot停止,这意味着没有人可以使用它。
确保导入异步IO
您还可以将其设置为命令,而不是使用如果message.content.startswith('href:'randgame'):
,则可以使用
import discord
import os
import random
import asyncio
from discord.ext import commands
client = discord.Client()
horaact = time.strftime('%H:%M:%S')
os.system('cls')
os.system('color 1f')
@client.event
async def on_ready():
print("Encendido")
print("logged in as {0.user}".format(client))
@client.command()
async def ººrandgame(ctx):
message = await ctx.send("React to a number")
one = '1️⃣'
two = '2️⃣'
await message.add_reaction(one)
await message.add_reaction(two)
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in [one, two]
member = ctx.author
while True:
try:
reaction, user = await client.wait_for("reaction_add", timeout=600.0, check=check)
if str(reaction.emoji) == one:
await ctx.send("You choose 1")
if str(reaction.emoji) == two:
await ctx.send("You choose 2")
client.run('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
我觉得少了点什么
请记住,这不是原始代码,它只是测试您的funtion@Dharman&Cohen非常感谢您的回答。但是当我尝试您的代码时,我遇到了一个问题,控制台摘录:{注意:被定义为:client=discord.client()}>>client.run('xxxxxxxxxxxxxxxxxxxx'))>>^>>>>缩进错误:意外的缩进我打开了一个新的.py进行测试,错误是一样的。我将在另一个注释中粘贴测试代码。From已经非常感谢;)。@Santa这不是来自此代码。您自己的代码中有不正确的缩进。可能在行附近,如果(reaction.emoji==“1️⃣"):代码>。