【问题标题】:Custom DM command Discord.py自定义 DM 命令 Discord.py
【发布时间】:2021-02-05 05:54:41
【问题描述】:

我一直在四处寻找,我试图找出如何编写这样的自定义 DM 命令,例如“!welcome @user”,这将向他们发送一条消息,其中包含所有规则并欢迎他们加入服务器

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    我建议您尝试搜索更多内容,下次请发布您“尝试过的”代码,因为这有助于人们知道您已经尝试过,而不是纯粹依靠 StackOverflow 来给您答案。

    这里我举了一个成员 dm 的简单例子,你调用命令,提及成员,然后发送消息。由您来自定义此命令。

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

    针对您的问题进行了更多构建,您只能使用成员运行此命令,它会从 rules 变量发送规则

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

    【讨论】:

      猜你喜欢
      • 2021-05-17
      • 2019-08-22
      • 1970-01-01
      • 2021-05-20
      • 2021-04-26
      • 2020-03-31
      • 2021-03-19
      • 1970-01-01
      • 2021-10-15
      相关资源
      最近更新 更多