自动删除在特定频道中发送的消息
Auto-delete messages sent in a specific channel
我很好奇是否有人可以帮助我。
我的bot有一个建议通道,供玩家提供建议,让服务器变得更好。
但是,由于他们聊天,它会聚集在一起。我很好奇是否有办法删除特定频道中的任何消息,机器人命令除外?
谢谢!
好吧,您可以检查消息是否以您的前缀开头或是否由机器人发送:如果 none 其中,则表示它既不是命令也不是命令响应。所有这些都假设消息在该频道中。
// ASSUMPTIONS:
// channel = your channel as a TextChannel
// prefix = your prefix as a string
// owner = you as a User
client.on('message', msg => {
if (msg.channel != channel || msg.author.bot || msg.content.startsWith(prefix)) return;
else msg.delete();
});
// if you want your messages to be ignored too:
client.on('message', msg => {
if (msg.channel != channel || msg.author.bot || msg.content.startsWith(prefix) || msg.author == owner) return;
else msg.delete();
});
我很好奇是否有人可以帮助我。
我的bot有一个建议通道,供玩家提供建议,让服务器变得更好。
但是,由于他们聊天,它会聚集在一起。我很好奇是否有办法删除特定频道中的任何消息,机器人命令除外?
谢谢!
好吧,您可以检查消息是否以您的前缀开头或是否由机器人发送:如果 none 其中,则表示它既不是命令也不是命令响应。所有这些都假设消息在该频道中。
// ASSUMPTIONS:
// channel = your channel as a TextChannel
// prefix = your prefix as a string
// owner = you as a User
client.on('message', msg => {
if (msg.channel != channel || msg.author.bot || msg.content.startsWith(prefix)) return;
else msg.delete();
});
// if you want your messages to be ignored too:
client.on('message', msg => {
if (msg.channel != channel || msg.author.bot || msg.content.startsWith(prefix) || msg.author == owner) return;
else msg.delete();
});