【问题标题】:How to get name of person calling a command in discord.py如何在 discord.py 中获取调用命令的人的姓名
【发布时间】:2020-06-07 00:12:45
【问题描述】:

好吧,我 12 岁,对任何“愚蠢”感到抱歉,好吧,我制作了一个不和谐的机器人,到目前为止它还不错,但是有一个问题,我们如何检查是否有人调用了命令?例如:

@client.commands()
     async def sayname(ctx):
     await ctx.send(f'Your name is {HowToGetName}')

是否可以添加两个参数,例如 sayname(ctx, member),因为我试过了,但没有用:(请帮忙。

编辑:如果这有助于我使用 Python 3.8.1

import discord
from discord.ext import commands
import random
import json

client = commands.Bot(command_prefix = ";")

@client.event
async def on_ready():
    print("Bot is ready.")

@client.event
async def on_member_join(member):
    print(f'{member} Joined the server!')

@client.command()
async def ping(ctx):
    await ctx.send(f'Pong! Server Ping: {round(client.latency * 1000)}ms.')

@client.command()
async def coinflip(ctx):
    number = random.randrange(1, 3);
    if number == 1:
        await ctx.send('Tails!')
    else:
        await ctx.send('Heads!')

@client.command()
async def test():
    await ctx.send('This is a testing command.')



client.run("Token")

【问题讨论】:

  • 出了什么问题,为什么每个人都反对这个帖子?我现在不能再问另一个问题了:(

标签: python python-3.x discord.py


【解决方案1】:

您要查找的代码:

@client.command()
async def sayname(ctx):
    await ctx.send(f"Your name is {ctx.author.name}")

另一方面,不要在此处发布您的令牌。人们可以使用该令牌访问您的机器人。

【讨论】:

  • 哇,这也帮助分配了谢谢我忘记了我发布了我的令牌我现在会重新生成它,谢谢
猜你喜欢
  • 2021-09-25
  • 2021-07-03
  • 2020-10-26
  • 2020-08-02
  • 2021-09-20
  • 2021-07-26
  • 2016-05-07
  • 2015-01-27
相关资源
最近更新 更多