【问题标题】:Get the ID of a discord channel with a bot with discord.py使用 discord.py 获取不和谐频道的 ID
【发布时间】:2021-08-07 03:45:13
【问题描述】:

我正在编写一个机器人,它需要在用户激活它的频道中发送消息。我似乎不知道如何从消息中获取频道 ID。

@bot.command(name="start", description="Starts for a channel")
async def start(ctx):
     await ctx.send("Started")
     #Get channel ID here and assign it to the var channel


@tasks.loop(seconds=2)
async def message()
     channel = bot.get_channel(channel)
     await channel.send("Message")

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    要获取频道 ID,请使用 ctx.channel.id。但是,您已经可以将通道传递到 message 循环中。

    @bot.command(name="start", description="Starts for a channel")
    async def start(ctx):
         await ctx.send("Started")
         message.start(ctx.channel)
    
    
    @tasks.loop(seconds=2)
    async def message(channel):
         await channel.send("Message")
    

    【讨论】:

      猜你喜欢
      • 2022-01-16
      • 2017-09-18
      • 2020-11-01
      • 2022-10-05
      • 2019-10-11
      • 2021-11-15
      • 2020-07-05
      • 2019-03-25
      相关资源
      最近更新 更多