Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have been looking around for ages im trying to find out how to code a custom DM command like this for example "!welcome @user" and that will send them a message that will put all the rules and welcome them to the server

question from:https://stackoverflow.com/questions/66054070/custom-dm-command-discord-py

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
525 views
Welcome To Ask or Share your Answers For Others

1 Answer

I would recommend trying to search some more, and next time please post your "attempted" code, as this helps people know that you have tried and not purely relying StackOverflow to give you an answer.

Here I have given a simple example of a member dm, you call the command, mention a member, then sending a message. Ill leave it up to you to customize this command.

@client.command()
async def welcome(ctx, member: discord.Member, *, message=None):
        await member.send(message)
        await ctx.send(f'You successfully sent a message to {member}')

A little more built to your question, you can run this command only with a member and it would send the rules from the rules variable

@client.command()
async def welcome(ctx, member: discord.Member):

        rules = """
Welcome, user to our server. 
please read the rules we have set for our server

 1. Have respect
 2. Be nice
 3. And so on..."""

        await member.send(rules)
        await ctx.send(f'You successfully sent a message to {member}')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...