如何让机器人将频道 ID 设置为消息内容

时间:2021-06-08 06:18:00

标签: discord.py

我想让我的机器人发送询问主频道 ID 像机器人频道等。如何让我的机器人意识到用户发送的消息是频道 ID 以及如何做?

我的python代码:

import discord 
from discord.ext import commands

@client.command()
async def channelset(ctx):
  embed=discord.Embed(title='Channel-Set',description='Put in your channel ID')
  await ctx.send(embed=embed)

# replace token with actual token
client.run(token)

2 个答案:

答案 0 :(得分:0)

您可以在命令中使用 wait_for() 函数。这是一个关于它的小例子:

def check(m):
    return m.content == 'hello' and m.channel == channel

msg = await client.wait_for('message', check=check)
await channel.send('Hello {.author}!'.format(msg))

但是,您需要自己弄清楚获取频道 ID。此示例检查“hello”。

答案 1 :(得分:0)

添加到 Emir Sürmen 的回答中,您可以编译服务器中的所有文本频道,使用它们的 id 创建一个新列表,然后检查:

if int(msg) in id_list:
    #code
else:
    ctx.send("Invalid channel id")

或类似的东西。