Discord Bot无法按名称获取频道

Leo*_*Leo 7 javascript bots discord

我一直在制作一个不和谐机器人,并希望让它向特定的"欢迎"频道发送消息.不幸的是,我无法这样做.我试过这个.

const welcomeChannel = bot.channels.get("name", "welcome")
welcomeChannel.sendMessage("Welcome\n"+member.user.username);
Run Code Online (Sandbox Code Playgroud)

但是在这个"welcomeChannel未定义"中.

编辑:

我试过用

const welcomeChannel = bot.channels.get("id", "18NUMBERIDHERE")
welcomeChannel.sendMessage("Welcome\n"+member.user.username);
Run Code Online (Sandbox Code Playgroud)

但奇怪的是,这仍然是未定义的

Der*_*ddy 17

你应该使用channnel id而不是它的名字.

如何获取频道的频道ID:

  1. 打开您的Discord设置

  2. Appearance

  3. 勾选Developer Mode(并关闭Discord设置)

  4. 右键单击所需的频道

  5. 现在可以选择Copy ID复制频道ID

还要查看discord.js文档中的(频道)集合


此外,您的方法将无法工作,因为需要.get一个频道ID(请参阅上面的链接文档).如果你真的想要通过它的名字获得一个频道,请使用.find它.
但是,如果您的机器人在多个服务器上运行,这是一个非常糟糕的主意,因为通道名称现在可以多次出现.

  • @FishProHD它是`bot.channels.get("18NUMBERIDHERE")`,而不是`bot.channels.get("id","18NUMBERIDHERE")` (2认同)

小智 7

您也可以使用

bot.channels.find("name","welcome").send("Welcome!")
Run Code Online (Sandbox Code Playgroud)