[英]How to use a channel, which is provided in a slashcommand received before in a onMessageReveived event?
I started coding a new project today and I'm having some issues.我今天开始编写一个新项目,但遇到了一些问题。 The bot should check every message in a channel provided in a slash command whether it's equal to a word, also provided in the slash command.
机器人应检查斜杠命令中提供的频道中的每条消息是否等于单词,斜杠命令中也提供了该单词。 For that I would normally need an onMessageReceived event, but I can't use something, which was provided in a slash command there.
为此,我通常需要一个 onMessageReceived 事件,但我不能使用那里的斜线命令中提供的东西。 Has anyone an idea how to fix that?
有谁知道如何解决这个问题?
I tried some things, but you can't make a public string in an onSlashCommandInteractionEvent.我尝试了一些方法,但您不能在 onSlashCommandInteractionEvent 中创建公共字符串。 I don't know how I could fix that problem otherwise, because I would normally do something like
我不知道如何解决这个问题,因为我通常会做类似的事情
event.getOption("channel").getAsChannel().asTextChannel()
but you can only do that in the event.但你只能在活动中这样做。 There you can't use it in another event though.
在那里你不能在另一个事件中使用它。
You have to store the data on the channel somewhere, preferably in a separate file, but you can also make a public List<TextChannel>
and work on that, only problem being it will be reset every time you restart the project.您必须将数据存储在通道上的某个地方,最好是在一个单独的文件中,但您也可以创建一个公共
List<TextChannel>
并对其进行处理,唯一的问题是每次重新启动项目时它都会被重置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.