from discord.ext import commands
bot = commands.Bot()
allowed_role_id = 1234567890 # just an example, i will replace with the ID of the allowed role
@bot.event
async def on_ready():
print(f'Logged in as {bot.user} (ID: {bot.user.id})')
@bot.command(name='sendmessage')
@commands.has_role(allowed_role_id)
async def send_message(ctx, *, message: str):
for member in ctx.guild.members:
if not member.bot:
dm_channel = await member.create_dm()
sent_message = await dm_channel.send(message)
await sent_message.add_reaction("✅")
await sent_message.add_reaction("❌")
await sent_message.add_reaction("")
@bot.event
async def on_raw_reaction_add(payload):
member = bot.get_user(payload.user_id) # Using the user_id here
if member == bot.user:
return
guild = bot.get_guild(1077548297037819985) # Since this is in a dm, use the integer value for your guild.
member = guild.get_member(payload.user_id)
channel = bot.get_channel(payload.channel_id)
message = await channel.fetch_message(payload.message_id)
if message.author != bot.user:
return
log_channel = bot.get_channel(1095793300184764477)
embed = discord.Embed(title="Reaction Log", color=0x00ff00)
embed.add_field(name="User", value=f"{member.mention} ({member.id})", inline=True)
embed.add_field(name="Reaction", value=payload.emoji.name, inline=True)
embed.add_field(name="Roles", value=" ".join([role.mention for role in member.roles]), inline=False)
embed.add_field(name="Nickname", value=member.nick, inline=True)
embed.add_field(name="Joined At", value=member.joined_at.strftime("%Y-%m-%d %H:%M:%S"), inline=True)
await log_channel.send(embed=embed)
I expect it to log once, and send once, tried debugging it for 2 hours didn't work.
Note also there is another picture that it also sends twice when I do !sendmessage
.
Hope can someone send me what I'm doing wrong and send me a modified code that fixes it, thanks.