【问题标题】:Edit message in a specific channel in a specific guild | Discord.js在特定公会的特定频道中编辑消息 |不和谐.js
【发布时间】:2019-05-12 15:03:27
【问题描述】:

你好
(我是法国人,很抱歉我的英语不好)

我希望我的机器人编辑特定频道中的消息,我尝试了很多代码,但没有一个起作用。

let channels = Bot.guilds.find(g => g.id == "guild id").channels.filter(c => c.id == "another guild id").array();

channels.forEach(channel => {
     channel.fetchMessage("message id").edit("Message Edited");
);

我也尝试使用for 等... channel 已定义,但它无法获取任何消息...


我也不知道我能不能做到...

谢谢你帮助我!

【问题讨论】:

    标签: discord.js


    【解决方案1】:

    您可以使用get()find() 方法来执行此操作,如下所示。

    // Note: This code must be inside of an async function.
    
    const guild = bot.guilds.get('guildIDhere');
    if (!guild) return console.log('Unable to find guild.');
    
    const channel = guild.channels.find(c => c.id === 'channelIDhere' && c.type === 'text');
    if (!channel) return console.log('Unable to find channel.');
    
    try {
        const message = await channel.fetchMessage('messageIDhere');
        if (!message) return console.log('Unable to find message.');
    
        await message.edit('Test.');
        console.log('Done.');
    } catch(err) {
        console.error(err);
    }
    

    【讨论】:

      猜你喜欢
      • 2021-04-15
      • 2022-01-25
      • 2020-11-06
      • 1970-01-01
      • 2019-04-11
      • 2021-08-17
      • 2020-07-14
      • 2020-12-30
      • 2019-12-28
      相关资源
      最近更新 更多