简体   繁体   English

如何在 discord.js 中使用我自己的“say”命令向特定频道发送消息?

[英]How can I send a message to a specific channel by using my own "say" command in discord.js?

I tried to make a code like I write.say blabla" in another channel and It will delete my channel and send my message to "#general" but I can't find a code to do this.我试图在另一个频道中制作一个像我 write.say blabla" 这样的代码,它会删除我的频道并将我的消息发送到 "#general" 但我找不到执行此操作的代码。

client.on('message', message => {
    if (message.content.startsWith(prefix + 'ç')) {
        if (message.author.bot) return;
        message.delete()
        const SayMessage = message.content.slice(2).trim();
        message.channel.send(SayMessage)

Here is the code.这是代码。 Can you help me?你能帮助我吗?

You are doing message.delete() first and then after that, you are doing message.content .您首先在做message.delete() ,然后在做message.content In this case, the message.content will be null and you cant send an empty message.在这种情况下, message.content将为 null 并且您不能发送空消息。 So first assign the message content to SayMessage and then delete the message.所以先将消息内容分配给SayMessage ,然后再删除消息。 Also if you need to send to another specific channel, you need to get the channel, and then send it there.此外,如果您需要发送到另一个特定频道,则需要获取该频道,然后将其发送到那里。

Eg:例如:

if (message.author.bot) return;
if (message.content.startsWith(prefix + 'ç')) {
        const SayMessage = message.content.slice(2).trim();
        message.delete();
        const Mchannel = message.guild.channels.cache.get('the-channel-id');
        Mchannel.send(SayMessage);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM