I ran into an issue when making this discord bot. Whenever a user runs the command !!bug
, there shall be a private message where the user has to answer a few questions. The issue is that whenever you run the command, you can still answer the question in the chat you ran the command.
I want it to only wait for the user response if the user wrote in private messages, and not the chat the command was run at. So this line of code:
responseDesc = await self.client.wait_for('message', check=lambda message: message.author == ctx.author, timeout=300)
Should only work when the user writes in private messages.
Here is my code:
import discord
from discord.ext import commands
import asyncio
emojis = ["\u2705", "\U0001F6AB", "\u274C"]
class Bug(commands.Cog):
def __init__(self, client):
self.client = client
@commands.command()
async def bug(self, ctx, desc=None, rep=None):
await ctx.channel.purge(limit=1)
user = ctx.author
await ctx.author.send('```Please explain the bug```')
responseDesc = await self.client.wait_for('message', check=lambda message: message.author == ctx.author, timeout=300)
description = responseDesc.content
await ctx.author.send('```Please provide pictures/videos of this bug```')
responseRep = await self.client.wait_for('message', check=lambda message: message.author == ctx.author, timeout=300)
replicate = responseRep.content
await ctx.author.send('Your bug report has been sent.')
embed = discord.Embed(title='Bug Report', color=0x00ff00)
embed.add_field(name='Description',
value=description, inline=False)
embed.add_field(name='Replicate', value=replicate, inline=True)
embed.add_field(name='Reported By', value=user, inline=True)
adminBug = self.client.get_channel(733721953134837861)
message = await adminBug.send(embed=embed)
for emoji in emojis:
await message.add_reaction(emoji)
@commands.Cog.listener()
async def on_reaction_add(self, reaction, user):
reaction_message = reaction.message
message = await reaction_message.channel.fetch_message(reaction_message.id)
my_embed = message.embeds[0]
emoji = reaction.emoji
if user.bot:
return
if emoji == "\u2705":
fixed_channel = self.client.get_channel(733722567449509958)
await fixed_channel.send(embed=my_embed)
elif emoji == "\U0001F6AB":
notBug = self.client.get_channel(733722584801083502)
await notBug.send(embed=my_embed)
elif emoji == "\u274C":
notFixed = self.client.get_channel(733722600706146324)
await notFixed.send(embed=my_embed)
else:
return
def setup(client):
client.add_cog(Bug(client))
您可以检查频道是否是私有的,例如if isinstance(message.channel, discord.DMChannel)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.