[英]Can't use you Telegram Bot API functions if the namespace and class of the function in the method parameter
I have this code我有这个代码
public static void info()
{
TGKrybot.SendTextMessageAsync(Telegram.Bot.Args.MessageEventArgs.Message.Chat.Id, "example");
}
and this code和这段代码
public static void mybot_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs msg)
In the first code, i cant use Telegram.Bot.Args.MessageEventArgs.Message.Chat.Id
(and other telegram bot API code ofcourse) even though ive put using static Telegram.Bot.Args.MessageEventArgs
in the beginning, the problem is is it needs MessageEventArgs.Message
to be an object, but when i create an object for it it says that theres no Message
property, method or field in MessageEventArgs
, ive also tried creating an object for Telegram.Bot.Args.MessageEventArgs.Message
and that doesnt work because object needs parameters which this doesn't have.在第一个代码中,我不能使用
Telegram.Bot.Args.MessageEventArgs.Message.Chat.Id
(当然还有其他电报机器人 API 代码),即使我一开始就using static Telegram.Bot.Args.MessageEventArgs
,问题是它是否需要MessageEventArgs.Message
为 object,但是当我为其创建 object 时,它表示MessageEventArgs
中没有Message
属性、方法或字段,我还尝试为Telegram.Bot.Args.MessageEventArgs.Message
创建 object 和这不起作用,因为 object 需要它没有的参数。 And i can't say it in the parameters of the 1st code like i did for the 2nd code because i need the 1st code as a function. How can i fix this, i also don't understand how putting Telegram.Bot.Args.MessageEventsArgs
in the parameters of my method allows me to use telegram API code.而且我不能像在第二个代码中那样在第一个代码的参数中说它,因为我需要第一个代码作为 function。我该如何解决这个问题,我也不明白如何将
Telegram.Bot.Args.MessageEventsArgs
我的方法参数中的 .MessageEventsArgs 允许我使用电报Telegram.Bot.Args.MessageEventsArgs
代码。
Your method must has parameters, if you want to do that in mybot_OnMessage
method, you can use msg
parameter, but in your case you must let info
has a Message
parameter, and pass it in mybot_OnMessage
to info
method, so it must be like this:你的方法必须有参数,如果你想在
mybot_OnMessage
方法中这样做,你可以使用msg
参数,但在你的情况下你必须让info
有一个Message
参数,并将它传递给mybot_OnMessage
到info
方法,所以它必须是这样的:
public static void mybot_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs msg)
{
info(msg.Message);
}
public static void info(dynamic m)
{
TGKrybot.SendTextMessageAsync(m.Chat.Id, "example");
}
Or you can use it with static class that have Message
field, but it's not good , like this:或者您可以将它与具有
Message
字段的 static class 一起使用,但效果不佳,如下所示:
public static class SharedValues
{
public static Message Message;
}
public static class Program
{
public static void mybot_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs msg)
{
SharedValues.Message = msg.Message;
}
}
public static class AnothorProject
{
public static void info()
{
// Use shared values class
TGKrybot.SendTextMessageAsync(SharedValues.Message.Chat.Id, "example")
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.