如何解决如何通过Discord机器人提及用户-python
我想编写一些代码来提及发送消息的用户名,这是我尝试过的:
对于制作不和谐的bot和python来说是新手,所以任何帮助都是完美的
@client.command()
async def hello(ctx,member):
await ctx.send(f"hello,{member}")
解决方法
您可以使用def insert(character):
old_entry_content = entry_name.get()
entry_name.delete(0,END)
entry_name.insert(0,old_entry + str(character))
user.name
@client.command()
async def hello(ctx):
await ctx.send(f"hello,{ctx.author.name}")
可以调用以上内容,即使您只是发送“ hello”(不带前缀),如果您想说“ hello {name}”,请使用{prefix}hello
事件。
on_message
,
这应该起作用: str(ctx.message.author) 要么: str(ctx.author)
,假设您要提及使用该命令的用户。 ctx
参数具有很多属性,其中之一是作者
@client.command()
async def hello(ctx,member):
await ctx.send(f"hello,{ctx.author}")
如果您希望用户与其他用户打招呼,他可以提及或直接输入名称。
@client.command()
async def hello(ctx,*,user: discord.Member = None):
if user:
await ctx.send(f"hello,{user.mention}")
else:
await ctx.send('You have to say who do you want to say hello to')
以上提供给您的所有信息都使用discord.ext.commands
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。