Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
380 views
in Technique[技术] by (71.8m points)

python - Custom DM command Discord.py

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

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

1 Reply

0 votes
by (71.8m points)

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}')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...