Search code examples
discorddiscord.pynextcord

How to make an annoucement command that can only triggered by me in dm (nextcord)


So, I am going to make an announcement command that only can triggered by me and by dm the bot

@client.command(pass_context=True)
@commands.has_any_role('BasicLolGaming', 'MODERATOR', 442186820977950720)
async def pemberitauan(ctx):
    embed= nextcord.Embed(
        color= nextcord.Color.dark_red()
    )
    embed.set_author(name='Kentod', icon_url='https://cdn.discordapp.com/avatars/707853874895126598/fd92dfd8c389bf9f2ba7a756df4b2681.webp?size=48')
    embed.set_image(url='https://cdn.discordapp.com/attachments/865242702668759100/902717752605806612/unknown.png')

    channel = client.get_channel(803585009692835851)
    await channel.send(embed=embed)

This code works for me only if I write the command on the server. But, I want it to be triggered in code by dm the bot.


Solution

  • Use @commands.is_owner() check instead of @commands.has_any_role('BasicLolGaming', 'MODERATOR', 442186820977950720). And add owner_ids=[your_id] kwarg in your client initialization. For example

    client = Bot(command_prefix="!", owner_ids=[your_id])