python - 作者频道名称
问题描述
我希望它输入文本频道名称,但它不起作用请帮忙
@client.command()
async def lock(ctx):
channel = ctx.message.author.discord.text_channel.name
server = ctx.message.guild
overwrites_everyone = ctx.message.channel.overwrites_for(server.default_role)
overwrites_everyone.send_messages = False
await ctx.message.channel.set_permissions(server.default_role, overwrite=overwrites_everyone)
await ctx.send(f"{channel} it is closed ")
解决方案
从ctx
(Context) 对象中,您可以通过ctx.channel
. 它返回一个TextChannel
对象,然后您可以从中获取其他属性:
@bot.command()
async def whereami(ctx):
await ctx.send(f"You're in a channel called {ctx.channel} ({ctx.channel.mention})!")
如示例中所示,您可以通过访问该.mention
属性来获得频道的提及。这相当于f"<#{ctx.channel.id}>"
将通道对象转换为字符串时,它会显示通道的名称。它相当于ctx.channel.name
.
参考:
推荐阅读
- javascript - 处理脚本 3
- android - Ionic4:绑定无法从外部设备工作
- leaflet - 为什么捕捉在 Leaflet 1.0.0 及更高版本上不起作用?
- google-cloud-data-fusion - 如何在 Data Fusion Studio 中将节点的输出作为属性变量传递给下一个节点
- java - 实现 Pagefactory 和显式等待时出错
- swift - 在 Swift 中的手机启动时运行应用程序
- google-apps-script - 基于 TypeError 触发的函数失败:在对象 FULL 中找不到函数 getMessages
- django - 如何配置 uwsgi + nginx + Django + websocket?
- java - Java 条件循环
- ios - 为什么没有分配相同的闭包类型